⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 242917 in webkit


Ignore:
Timestamp:
Mar 13, 2019, 4:18:26 PM (7 years ago)
Author:
Wenson Hsieh
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.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r242914 r242917  
     12019-03-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Fix an edge case where HTMLFormElement::removeFormElement is invoked twice with the same element
     4        https://bugs.webkit.org/show_bug.cgi?id=195663
     5        <rdar://problem/48576391>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add a layout test to exercise the scenario described in the WebCore ChangeLog.
     10
     11        * fast/forms/remove-associated-element-after-gc-expected.txt: Added.
     12        * fast/forms/remove-associated-element-after-gc.html: Added.
     13
    1142019-03-13  Nikita Vasilyev  <nvasilyev@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r242915 r242917  
     12019-03-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Fix an edge case where HTMLFormElement::removeFormElement is invoked twice with the same element
     4        https://bugs.webkit.org/show_bug.cgi?id=195663
     5        <rdar://problem/48576391>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Currently, it's possible for HTMLFormControlElement's destructor to be reentrant. This may happen if the form
     10        control element is ref'd while carrying out its destructor's logic. This may happen in two places in
     11        HTMLFormControlElement (didChangeForm and resetDefaultButton), both of which actually don't require ensuring a
     12        protected reference to the form control element since they should never result in any script execution.
     13
     14        To fix the bug, convert these strong references into raw pointers, and add ScriptDisallowedScope to ensure that
     15        we don't change these codepaths in the future, such that they trigger arbitrary script execution.
     16
     17        Test: fast/forms/remove-associated-element-after-gc.html
     18
     19        * html/HTMLFormControlElement.cpp:
     20        (WebCore::HTMLFormControlElement::didChangeForm):
     21        * html/HTMLFormElement.cpp:
     22        (WebCore::HTMLFormElement::resetDefaultButton):
     23
    1242019-03-13  Daniel Bates  <dabates@apple.com>
    225
  • trunk/Source/WebCore/html/HTMLFormControlElement.cpp

    r242792 r242917  
    4242#include "RenderBox.h"
    4343#include "RenderTheme.h"
     44#include "ScriptDisallowedScope.h"
    4445#include "Settings.h"
    4546#include "StyleTreeResolver.h"
     
    558559void HTMLFormControlElement::didChangeForm()
    559560{
     561    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     562
    560563    FormAssociatedElement::didChangeForm();
    561     if (RefPtr<HTMLFormElement> form = this->form()) {
     564    if (auto* form = this->form()) {
    562565        if (m_willValidateInitialized && m_willValidate && !isValidFormControlElement())
    563566            form->registerInvalidAssociatedFormControl(*this);
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r241932 r242917  
    705705    }
    706706
    707     RefPtr<HTMLFormControlElement> oldDefault = m_defaultButton;
     707    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     708
     709    auto* oldDefault = m_defaultButton;
    708710    m_defaultButton = nullptr;
    709711    defaultButton();
Note: See TracChangeset for help on using the changeset viewer.