Commit 09b4427e authored by Timothy Gu's avatar Timothy Gu Committed by Commit Bot

document.open(): Check frame_ after StopAllLoaders

FrameLoader::StopAllLoaders() has this explicit note:

    Warning: stopAllLoaders can and will detach the LocalFrame out from
    under you. All callers need to either protect the LocalFrame or
    guarantee they won't in any way access the LocalFrame after
    stopAllLoaders returns.

Check frame_'s existence after the call to prevent a NULL dereference.

Bug: 879366
Change-Id: I1e537374f59fbad7b069f9de63cfa3b6b2b2b00c
Reviewed-on: https://chromium-review.googlesource.com/1198022Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Timothy Gu <timothygu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587933}
parent f507b26d
This tests that calling document.open on a document that has a pending load correctly cancels the load and does not crash even if the frame is removed.
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
<body>
This tests that calling document.open on a document that has a pending load correctly cancels the load and does not crash even if the frame is removed.
<script>
const div = document.body.appendChild(document.createElement("div"));
div.innerHTML = "<iframe src='data:text/html,'></iframe>";
const frame = div.childNodes[0];
const client = new frame.contentWindow.XMLHttpRequest();
client.open("GET", "data:text/html,");
client.onabort = e => {
div.remove();
};
client.send();
frame.contentWindow.document.open();
</script>
</body>
...@@ -3108,7 +3108,7 @@ void Document::open() { ...@@ -3108,7 +3108,7 @@ void Document::open() {
if (frame_ && frame_->Loader().HasProvisionalNavigation()) { if (frame_ && frame_->Loader().HasProvisionalNavigation()) {
frame_->Loader().StopAllLoaders(); frame_->Loader().StopAllLoaders();
// Navigations handled by the client should also be cancelled. // Navigations handled by the client should also be cancelled.
if (frame_->Client()) if (frame_ && frame_->Client())
frame_->Client()->AbortClientNavigation(); frame_->Client()->AbortClientNavigation();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment