Title: [249996] branches/safari-608-branch/Source/WebCore
- Revision
- 249996
- Author
- [email protected]
- Date
- 2019-09-17 15:29:38 -0700 (Tue, 17 Sep 2019)
Log Message
Cherry-pick r249762. rdar://problem/55427465
Prevent reentrancy FrameLoader::dispatchUnloadEvents()
https://bugs.webkit.org/show_bug.cgi?id=200738
Reviewed by Brady Eidson.
Reentrancy causes m_pageDismissalEventBeingDispatched to be incorrectly
updated, so don't allow reentrancy.
Since this prevents m_pageDismissalEventBeingDispatched from being reset
inside a reentrant call, it can have the unintended effect of causing
FrameLoader::stopAllLoaders to early-out when called from
FrameLoader::detachFromParent while a frame's unload event handler
calls document.open() on a parent frame and causes itself to become
detached. Allowing a load to continue in a detached frame will lead to
a crash. To prevent this, add a new argument to FrameLoader::stopAllLoaders
that FrameLoader::detachFromParent can use to prevent an early-out.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::stopAllLoaders):
(WebCore::FrameLoader::detachFromParent):
(WebCore::FrameLoader::dispatchUnloadEvents):
(WebCore::FrameLoader::dispatchBeforeUnloadEvent):
Ensure that m_pageDismissalEventBeingDispatched is reset to its previous value, even if this is not None.
* loader/FrameLoader.h:
* loader/FrameLoaderTypes.h:
Add a StopLoadingPolicy enum.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249762 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-608-branch/Source/WebCore/ChangeLog (249995 => 249996)
--- branches/safari-608-branch/Source/WebCore/ChangeLog 2019-09-17 22:29:36 UTC (rev 249995)
+++ branches/safari-608-branch/Source/WebCore/ChangeLog 2019-09-17 22:29:38 UTC (rev 249996)
@@ -1,5 +1,67 @@
2019-09-17 Kocsen Chung <[email protected]>
+ Cherry-pick r249762. rdar://problem/55427465
+
+ Prevent reentrancy FrameLoader::dispatchUnloadEvents()
+ https://bugs.webkit.org/show_bug.cgi?id=200738
+
+ Reviewed by Brady Eidson.
+
+ Reentrancy causes m_pageDismissalEventBeingDispatched to be incorrectly
+ updated, so don't allow reentrancy.
+
+ Since this prevents m_pageDismissalEventBeingDispatched from being reset
+ inside a reentrant call, it can have the unintended effect of causing
+ FrameLoader::stopAllLoaders to early-out when called from
+ FrameLoader::detachFromParent while a frame's unload event handler
+ calls document.open() on a parent frame and causes itself to become
+ detached. Allowing a load to continue in a detached frame will lead to
+ a crash. To prevent this, add a new argument to FrameLoader::stopAllLoaders
+ that FrameLoader::detachFromParent can use to prevent an early-out.
+
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::stopAllLoaders):
+ (WebCore::FrameLoader::detachFromParent):
+ (WebCore::FrameLoader::dispatchUnloadEvents):
+ (WebCore::FrameLoader::dispatchBeforeUnloadEvent):
+ Ensure that m_pageDismissalEventBeingDispatched is reset to its previous value, even if this is not None.
+ * loader/FrameLoader.h:
+ * loader/FrameLoaderTypes.h:
+ Add a StopLoadingPolicy enum.
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249762 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-11 Ali Juma <[email protected]>
+
+ Prevent reentrancy FrameLoader::dispatchUnloadEvents()
+ https://bugs.webkit.org/show_bug.cgi?id=200738
+
+ Reviewed by Brady Eidson.
+
+ Reentrancy causes m_pageDismissalEventBeingDispatched to be incorrectly
+ updated, so don't allow reentrancy.
+
+ Since this prevents m_pageDismissalEventBeingDispatched from being reset
+ inside a reentrant call, it can have the unintended effect of causing
+ FrameLoader::stopAllLoaders to early-out when called from
+ FrameLoader::detachFromParent while a frame's unload event handler
+ calls document.open() on a parent frame and causes itself to become
+ detached. Allowing a load to continue in a detached frame will lead to
+ a crash. To prevent this, add a new argument to FrameLoader::stopAllLoaders
+ that FrameLoader::detachFromParent can use to prevent an early-out.
+
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::stopAllLoaders):
+ (WebCore::FrameLoader::detachFromParent):
+ (WebCore::FrameLoader::dispatchUnloadEvents):
+ (WebCore::FrameLoader::dispatchBeforeUnloadEvent):
+ Ensure that m_pageDismissalEventBeingDispatched is reset to its previous value, even if this is not None.
+ * loader/FrameLoader.h:
+ * loader/FrameLoaderTypes.h:
+ Add a StopLoadingPolicy enum.
+
+2019-09-17 Kocsen Chung <[email protected]>
+
Cherry-pick r249748. rdar://problem/55240888
Nullptr crash in Page::sessionID() via WebKit::WebFrameLoaderClient::detachedFromParent2()
Modified: branches/safari-608-branch/Source/WebCore/loader/FrameLoader.cpp (249995 => 249996)
--- branches/safari-608-branch/Source/WebCore/loader/FrameLoader.cpp 2019-09-17 22:29:36 UTC (rev 249995)
+++ branches/safari-608-branch/Source/WebCore/loader/FrameLoader.cpp 2019-09-17 22:29:38 UTC (rev 249996)
@@ -1808,12 +1808,12 @@
loadWithDocumentLoader(loader.ptr(), frameLoadTypeForReloadOptions(options), { }, AllowNavigationToInvalidURL::Yes, ShouldTreatAsContinuingLoad::No);
}
-void FrameLoader::stopAllLoaders(ClearProvisionalItemPolicy clearProvisionalItemPolicy)
+void FrameLoader::stopAllLoaders(ClearProvisionalItemPolicy clearProvisionalItemPolicy, StopLoadingPolicy stopLoadingPolicy)
{
if (m_frame.document() && m_frame.document()->pageCacheState() == Document::InPageCache)
return;
- if (!isStopLoadingAllowed())
+ if (stopLoadingPolicy == StopLoadingPolicy::PreventDuringUnloadEvents && !isStopLoadingAllowed())
return;
// If this method is called from within this method, infinite recursion can occur (3442218). Avoid this.
@@ -2821,7 +2821,7 @@
// stopAllLoaders() needs to be called after detachChildren() if the document is not in the page cache,
// because detachedChildren() will trigger the unload event handlers of any child frames, and those event
// handlers might start a new subresource load in this frame.
- stopAllLoaders();
+ stopAllLoaders(ShouldClearProvisionalItem, StopLoadingPolicy::AlwaysStopLoading);
}
InspectorInstrumentation::frameDetachedFromParent(m_frame);
@@ -3274,6 +3274,9 @@
if (!m_frame.document())
return;
+ if (m_pageDismissalEventBeingDispatched != PageDismissalType::None)
+ return;
+
// We store the frame's page in a local variable because the frame might get detached inside dispatchEvent.
ForbidPromptsScope forbidPrompts(m_frame.page());
IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document());
@@ -3352,15 +3355,13 @@
return true;
Ref<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create();
- m_pageDismissalEventBeingDispatched = PageDismissalType::BeforeUnload;
{
+ SetForScope<PageDismissalType> change(m_pageDismissalEventBeingDispatched, PageDismissalType::BeforeUnload);
ForbidPromptsScope forbidPrompts(m_frame.page());
domWindow->dispatchEvent(beforeUnloadEvent, domWindow->document());
}
- m_pageDismissalEventBeingDispatched = PageDismissalType::None;
-
if (!beforeUnloadEvent->defaultPrevented())
document->defaultEventHandler(beforeUnloadEvent.get());
Modified: branches/safari-608-branch/Source/WebCore/loader/FrameLoader.h (249995 => 249996)
--- branches/safari-608-branch/Source/WebCore/loader/FrameLoader.h 2019-09-17 22:29:36 UTC (rev 249995)
+++ branches/safari-608-branch/Source/WebCore/loader/FrameLoader.h 2019-09-17 22:29:38 UTC (rev 249996)
@@ -144,7 +144,7 @@
// FIXME: These are all functions which stop loads. We have too many.
void stopAllLoadersAndCheckCompleteness();
- WEBCORE_EXPORT void stopAllLoaders(ClearProvisionalItemPolicy = ShouldClearProvisionalItem);
+ WEBCORE_EXPORT void stopAllLoaders(ClearProvisionalItemPolicy = ShouldClearProvisionalItem, StopLoadingPolicy = StopLoadingPolicy::PreventDuringUnloadEvents);
WEBCORE_EXPORT void stopForUserCancel(bool deferCheckLoadComplete = false);
void stop();
void stopLoading(UnloadEventPolicy);
Modified: branches/safari-608-branch/Source/WebCore/loader/FrameLoaderTypes.h (249995 => 249996)
--- branches/safari-608-branch/Source/WebCore/loader/FrameLoaderTypes.h 2019-09-17 22:29:36 UTC (rev 249995)
+++ branches/safari-608-branch/Source/WebCore/loader/FrameLoaderTypes.h 2019-09-17 22:29:38 UTC (rev 249996)
@@ -141,6 +141,11 @@
ShouldNotClearProvisionalItem
};
+enum class StopLoadingPolicy {
+ PreventDuringUnloadEvents,
+ AlwaysStopLoading
+};
+
enum class ObjectContentType : uint8_t {
None,
Image,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes