Title: [242917] trunk
- Revision
- 242917
- Author
- [email protected]
- Date
- 2019-03-13 16:18:26 -0700 (Wed, 13 Mar 2019)
Log Message
Fix an edge case where HTMLFormElement::removeFormElement is invoked twice with the same element
https://bugs.webkit.org/show_bug.cgi?id=195663
<rdar://problem/48576391>
Reviewed by Ryosuke Niwa.
Source/WebCore:
Currently, it's possible for HTMLFormControlElement's destructor to be reentrant. This may happen if the form
control element is ref'd while carrying out its destructor's logic. This may happen in two places in
HTMLFormControlElement (didChangeForm and resetDefaultButton), both of which actually don't require ensuring a
protected reference to the form control element since they should never result in any script execution.
To fix the bug, convert these strong references into raw pointers, and add ScriptDisallowedScope to ensure that
we don't change these codepaths in the future, such that they trigger arbitrary script execution.
Test: fast/forms/remove-associated-element-after-gc.html
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::didChangeForm):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::resetDefaultButton):
LayoutTests:
Add a layout test to exercise the scenario described in the WebCore ChangeLog.
* fast/forms/remove-associated-element-after-gc-expected.txt: Added.
* fast/forms/remove-associated-element-after-gc.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (242916 => 242917)
--- trunk/LayoutTests/ChangeLog 2019-03-13 23:07:06 UTC (rev 242916)
+++ trunk/LayoutTests/ChangeLog 2019-03-13 23:18:26 UTC (rev 242917)
@@ -1,3 +1,16 @@
+2019-03-13 Wenson Hsieh <[email protected]>
+
+ Fix an edge case where HTMLFormElement::removeFormElement is invoked twice with the same element
+ https://bugs.webkit.org/show_bug.cgi?id=195663
+ <rdar://problem/48576391>
+
+ Reviewed by Ryosuke Niwa.
+
+ Add a layout test to exercise the scenario described in the WebCore ChangeLog.
+
+ * fast/forms/remove-associated-element-after-gc-expected.txt: Added.
+ * fast/forms/remove-associated-element-after-gc.html: Added.
+
2019-03-13 Nikita Vasilyev <[email protected]>
REGRESSION(r240946): Web Inspector: Styles: removing selected property doesn't update overridden status
Added: trunk/LayoutTests/fast/forms/remove-associated-element-after-gc-expected.txt (0 => 242917)
--- trunk/LayoutTests/fast/forms/remove-associated-element-after-gc-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/remove-associated-element-after-gc-expected.txt 2019-03-13 23:18:26 UTC (rev 242917)
@@ -0,0 +1 @@
+PASS
Added: trunk/LayoutTests/fast/forms/remove-associated-element-after-gc.html (0 => 242917)
--- trunk/LayoutTests/fast/forms/remove-associated-element-after-gc.html (rev 0)
+++ trunk/LayoutTests/fast/forms/remove-associated-element-after-gc.html 2019-03-13 23:18:26 UTC (rev 242917)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+input:default {
+ color: red;
+}
+</style>
+</head>
+<body>
+<table>
+<form><input type="submit"></form>
+</table>
+<p>This test passes if we avoid crashing, and if the green text "PASS" appears. This test requires DumpRenderTree or WebKitTestRunner.</p>
+</body>
+<script>
+if (window.testRunner) {
+ testRunner.waitUntilDone();
+ testRunner.dumpAsText();
+}
+
+document.addEventListener("DOMContentLoaded", () => {
+ let currentIteration = 1;
+ const href = ""
+ const index = href.lastIndexOf("#");
+ if (index !== -1)
+ currentIteration = parseInt(href.substring(index + 1));
+
+ if (currentIteration === 5) {
+ document.writeln("<pre style='color: green'>PASS</pre>");
+ if (window.testRunner)
+ testRunner.notifyDone();
+ return;
+ }
+
+ if (window.GCController)
+ GCController.collect();
+
+ location.href = "" index)}#${currentIteration + 1}`;
+ location.reload();
+}, false);
+</script>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (242916 => 242917)
--- trunk/Source/WebCore/ChangeLog 2019-03-13 23:07:06 UTC (rev 242916)
+++ trunk/Source/WebCore/ChangeLog 2019-03-13 23:18:26 UTC (rev 242917)
@@ -1,3 +1,26 @@
+2019-03-13 Wenson Hsieh <[email protected]>
+
+ Fix an edge case where HTMLFormElement::removeFormElement is invoked twice with the same element
+ https://bugs.webkit.org/show_bug.cgi?id=195663
+ <rdar://problem/48576391>
+
+ Reviewed by Ryosuke Niwa.
+
+ Currently, it's possible for HTMLFormControlElement's destructor to be reentrant. This may happen if the form
+ control element is ref'd while carrying out its destructor's logic. This may happen in two places in
+ HTMLFormControlElement (didChangeForm and resetDefaultButton), both of which actually don't require ensuring a
+ protected reference to the form control element since they should never result in any script execution.
+
+ To fix the bug, convert these strong references into raw pointers, and add ScriptDisallowedScope to ensure that
+ we don't change these codepaths in the future, such that they trigger arbitrary script execution.
+
+ Test: fast/forms/remove-associated-element-after-gc.html
+
+ * html/HTMLFormControlElement.cpp:
+ (WebCore::HTMLFormControlElement::didChangeForm):
+ * html/HTMLFormElement.cpp:
+ (WebCore::HTMLFormElement::resetDefaultButton):
+
2019-03-13 Daniel Bates <[email protected]>
Remove some unnecessary !USE(UIKIT_KEYBOARD_ADDITIONS) guards
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (242916 => 242917)
--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2019-03-13 23:07:06 UTC (rev 242916)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2019-03-13 23:18:26 UTC (rev 242917)
@@ -41,6 +41,7 @@
#include "Quirks.h"
#include "RenderBox.h"
#include "RenderTheme.h"
+#include "ScriptDisallowedScope.h"
#include "Settings.h"
#include "StyleTreeResolver.h"
#include "ValidationMessage.h"
@@ -557,8 +558,10 @@
void HTMLFormControlElement::didChangeForm()
{
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+
FormAssociatedElement::didChangeForm();
- if (RefPtr<HTMLFormElement> form = this->form()) {
+ if (auto* form = this->form()) {
if (m_willValidateInitialized && m_willValidate && !isValidFormControlElement())
form->registerInvalidAssociatedFormControl(*this);
}
Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (242916 => 242917)
--- trunk/Source/WebCore/html/HTMLFormElement.cpp 2019-03-13 23:07:06 UTC (rev 242916)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp 2019-03-13 23:18:26 UTC (rev 242917)
@@ -704,7 +704,9 @@
return;
}
- RefPtr<HTMLFormControlElement> oldDefault = m_defaultButton;
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+
+ auto* oldDefault = m_defaultButton;
m_defaultButton = nullptr;
defaultButton();
if (m_defaultButton != oldDefault) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes