Skip to content

Commit 1f00406

Browse files
TimothyGuspeednoisemovement
authored andcommitted
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/1198022 Reviewed-by: Nate Chapin <[email protected]> Reviewed-by: Kent Tamura <[email protected]> Reviewed-by: Hayato Ito <[email protected]> Commit-Queue: Timothy Gu <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#587933}(cherry picked from commit 09b4427) Reviewed-on: https://chromium-review.googlesource.com/1207612 Reviewed-by: Leonard Grey <[email protected]> Cr-Commit-Position: refs/branch-heads/3538@{#61} Cr-Branched-From: 79f7c91-refs/heads/master@{#587811}
1 parent c997eee commit 1f00406

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
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.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
if (window.testRunner)
3+
testRunner.dumpAsText();
4+
</script>
5+
<body>
6+
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.
7+
<script>
8+
const div = document.body.appendChild(document.createElement("div"));
9+
div.innerHTML = "<iframe src='data:text/html,'></iframe>";
10+
const frame = div.childNodes[0];
11+
const client = new frame.contentWindow.XMLHttpRequest();
12+
client.open("GET", "data:text/html,");
13+
client.onabort = e => {
14+
div.remove();
15+
};
16+
client.send();
17+
frame.contentWindow.document.open();
18+
</script>
19+
</body>

third_party/blink/renderer/core/dom/document.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3108,7 +3108,7 @@ void Document::open() {
31083108
if (frame_ && frame_->Loader().HasProvisionalNavigation()) {
31093109
frame_->Loader().StopAllLoaders();
31103110
// Navigations handled by the client should also be cancelled.
3111-
if (frame_->Client())
3111+
if (frame_ && frame_->Client())
31123112
frame_->Client()->AbortClientNavigation();
31133113
}
31143114

0 commit comments

Comments
 (0)