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

Changeset 109362 in webkit


Ignore:
Timestamp:
Mar 1, 2012, 10:19:03 AM (15 years ago)
Author:
inferno@chromium.org
Message:

Protect functions using two container node function, each of which can fire mutation events.
​https://bugs.webkit.org/show_bug.cgi?id=78397

Reviewed by Ryosuke Niwa.

Source/WebCore:

Tests: fast/dom/document-set-title-mutation-crash.html

fast/dom/option-text-mutation-crash.html

  • dom/Node.cpp:

(WebCore::Node::setTextContent):

  • dom/Text.cpp:

(WebCore::Text::replaceWholeText):

  • editing/markup.cpp:

(WebCore::trimFragment):
(WebCore::replaceChildrenWithFragment):
(WebCore::replaceChildrenWithText):

  • html/HTMLOptionElement.cpp:

(WebCore::HTMLOptionElement::setText):

  • html/HTMLScriptElement.cpp:

(WebCore::HTMLScriptElement::setText):

  • html/HTMLTableElement.cpp:

(WebCore::HTMLTableElement::insertRow):

  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::setDefaultValue):

  • html/HTMLTitleElement.cpp:

(WebCore::HTMLTitleElement::setText):

LayoutTests:

  • fast/dom/document-set-title-mutation-crash-expected.txt: Added.
  • fast/dom/document-set-title-mutation-crash.html: Added.
  • fast/dom/option-text-mutation-crash-expected.txt: Added.
  • fast/dom/option-text-mutation-crash.html: Added.
Location:
trunk
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109359 r109362  
     12012-03-01  Abhishek Arya  <inferno@chromium.org>
     2
     3        Protect functions using two container node function, each of which can fire mutation events.
     4        https://bugs.webkit.org/show_bug.cgi?id=78397
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/dom/document-set-title-mutation-crash-expected.txt: Added.
     9        * fast/dom/document-set-title-mutation-crash.html: Added.
     10        * fast/dom/option-text-mutation-crash-expected.txt: Added.
     11        * fast/dom/option-text-mutation-crash.html: Added.
     12
    1132012-03-01  Shinya Kawanaka  <shinyak@chromium.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r109360 r109362  
     12012-03-01  Abhishek Arya  <inferno@chromium.org>
     2
     3        Protect functions using two container node function, each of which can fire mutation events.
     4        https://bugs.webkit.org/show_bug.cgi?id=78397
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Tests: fast/dom/document-set-title-mutation-crash.html
     9               fast/dom/option-text-mutation-crash.html
     10
     11        * dom/Node.cpp:
     12        (WebCore::Node::setTextContent):
     13        * dom/Text.cpp:
     14        (WebCore::Text::replaceWholeText):
     15        * editing/markup.cpp:
     16        (WebCore::trimFragment):
     17        (WebCore::replaceChildrenWithFragment):
     18        (WebCore::replaceChildrenWithText):
     19        * html/HTMLOptionElement.cpp:
     20        (WebCore::HTMLOptionElement::setText):
     21        * html/HTMLScriptElement.cpp:
     22        (WebCore::HTMLScriptElement::setText):
     23        * html/HTMLTableElement.cpp:
     24        (WebCore::HTMLTableElement::insertRow):
     25        * html/HTMLTextAreaElement.cpp:
     26        (WebCore::HTMLTextAreaElement::setDefaultValue):
     27        * html/HTMLTitleElement.cpp:
     28        (WebCore::HTMLTitleElement::setText):
     29
    1302012-03-01  Alexey Proskuryakov  <ap@apple.com>
    231
  • trunk/Source/WebCore/dom/Node.cpp

    r109097 r109362  
    20602060        case ENTITY_REFERENCE_NODE:
    20612061        case DOCUMENT_FRAGMENT_NODE: {
    2062             ContainerNode* container = toContainerNode(this);
     2062            RefPtr<ContainerNode> container = toContainerNode(this);
    20632063#if ENABLE(MUTATION_OBSERVERS)
    20642064            ChildListMutationScope mutation(this);
  • trunk/Source/WebCore/dom/Text.cpp

    r99128 r109362  
    148148
    149149    RefPtr<Text> protectedThis(this); // Mutation event handlers could cause our last ref to go away
    150     ContainerNode* parent = parentNode(); // Protect against mutation handlers moving this node during traversal
     150    RefPtr<ContainerNode> parent = parentNode(); // Protect against mutation handlers moving this node during traversal
    151151    ExceptionCode ignored = 0;
    152152    for (RefPtr<Node> n = startText; n && n != this && n->isTextNode() && n->parentNode() == parent;) {
  • trunk/Source/WebCore/editing/markup.cpp

    r109251 r109362  
    694694{
    695695    ExceptionCode ec = 0;
    696     Node* next;
     696    RefPtr<Node> next;
    697697    for (RefPtr<Node> node = fragment->firstChild(); node; node = next) {
    698698        if (nodeBeforeContext->isDescendantOf(node.get())) {
    … …  
    708708
    709709    ASSERT(nodeAfterContext->parentNode());
    710     for (Node* node = nodeAfterContext; node; node = next) {
     710    for (RefPtr<Node> node = nodeAfterContext; node; node = next) {
    711711        next = node->traverseNextSibling();
    712         node->parentNode()->removeChild(node, ec);
     712        node->parentNode()->removeChild(node.get(), ec);
    713713        ASSERT(!ec);
    714714    }
    … …  
    10221022}
    10231023
    1024 void replaceChildrenWithFragment(ContainerNode* containerNode, PassRefPtr<DocumentFragment> fragment, ExceptionCode& ec)
    1025 {
     1024void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFragment> fragment, ExceptionCode& ec)
     1025{
     1026    RefPtr<ContainerNode> containerNode(container);
     1027
    10261028#if ENABLE(MUTATION_OBSERVERS)
    1027     ChildListMutationScope mutation(containerNode);
     1029    ChildListMutationScope mutation(containerNode.get());
    10281030#endif
    10291031
    … …  
    10331035    }
    10341036
    1035     if (hasOneTextChild(containerNode) && hasOneTextChild(fragment.get())) {
     1037    if (hasOneTextChild(containerNode.get()) && hasOneTextChild(fragment.get())) {
    10361038        toText(containerNode->firstChild())->setData(toText(fragment->firstChild())->data(), ec);
    10371039        return;
    10381040    }
    10391041
    1040     if (hasOneChild(containerNode)) {
     1042    if (hasOneChild(containerNode.get())) {
    10411043        containerNode->replaceChild(fragment, containerNode->firstChild(), ec);
    10421044        return;
    … …  
    10471049}
    10481050
    1049 void replaceChildrenWithText(ContainerNode* containerNode, const String& text, ExceptionCode& ec)
    1050 {
     1051void replaceChildrenWithText(ContainerNode* container, const String& text, ExceptionCode& ec)
     1052{
     1053    RefPtr<ContainerNode> containerNode(container);
     1054
    10511055#if ENABLE(MUTATION_OBSERVERS)
    1052     ChildListMutationScope mutation(containerNode);
     1056    ChildListMutationScope mutation(containerNode.get());
    10531057#endif
    10541058
    1055     if (hasOneTextChild(containerNode)) {
     1059    if (hasOneTextChild(containerNode.get())) {
    10561060        toText(containerNode->firstChild())->setData(text, ec);
    10571061        return;
    … …  
    10601064    RefPtr<Text> textNode = Text::create(containerNode->document(), text);
    10611065
    1062     if (hasOneChild(containerNode)) {
     1066    if (hasOneChild(containerNode.get())) {
    10631067        containerNode->replaceChild(textNode.release(), containerNode->firstChild(), ec);
    10641068        return;
  • trunk/Source/WebCore/html/HTMLOptionElement.cpp

    r107509 r109362  
    138138void HTMLOptionElement::setText(const String &text, ExceptionCode& ec)
    139139{
     140    RefPtr<Node> protectFromMutationEvents(this);
     141
    140142    // Changing the text causes a recalc of a select's items, which will reset the selected
    141143    // index to the first item if the select is single selection with a menu list. We attempt to
    142144    // preserve the selected item.
    143     HTMLSelectElement* select = ownerSelectElement();
     145    RefPtr<HTMLSelectElement> select = ownerSelectElement();
    144146    bool selectIsMenuList = select && select->usesMenuList();
    145147    int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1;
  • trunk/Source/WebCore/html/HTMLScriptElement.cpp

    r108165 r109362  
    8383void HTMLScriptElement::setText(const String &value)
    8484{
     85    RefPtr<Node> protectFromMutationEvents(this);
     86
    8587    ExceptionCode ec = 0;
    8688    int numChildren = childNodeCount();
  • trunk/Source/WebCore/html/HTMLTableElement.cpp

    r109149 r109362  
    188188    }
    189189
    190     HTMLTableRowElement* lastRow = 0;
    191     HTMLTableRowElement* row = 0;
     190    RefPtr<Node> protectFromMutationEvents(this);
     191
     192    RefPtr<HTMLTableRowElement> lastRow = 0;
     193    RefPtr<HTMLTableRowElement> row = 0;
    192194    if (index == -1)
    193195        lastRow = HTMLTableRowsCollection::lastRow(this);
    194196    else {
    195197        for (int i = 0; i <= index; ++i) {
    196             row = HTMLTableRowsCollection::rowAfter(this, lastRow);
     198            row = HTMLTableRowsCollection::rowAfter(this, lastRow.get());
    197199            if (!row) {
    198200                if (i != index) {
    … …  
    206208    }
    207209
    208     ContainerNode* parent;
     210    RefPtr<ContainerNode> parent;
    209211    if (lastRow)
    210212        parent = row ? row->parentNode() : lastRow->parentNode();
    … …  
    221223
    222224    RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document());
    223     parent->insertBefore(newRow, row, ec);
     225    parent->insertBefore(newRow, row.get(), ec);
    224226    return newRow.release();
    225227}
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r109149 r109362  
    385385void HTMLTextAreaElement::setDefaultValue(const String& defaultValue)
    386386{
     387    RefPtr<Node> protectFromMutationEvents(this);
     388
    387389    // To preserve comments, remove only the text nodes, then add a single text node.
    388 
    389390    Vector<RefPtr<Node> > textNodes;
    390391    for (Node* n = firstChild(); n; n = n->nextSibling()) {
  • trunk/Source/WebCore/html/HTMLTitleElement.cpp

    r107509 r109362  
    8989void HTMLTitleElement::setText(const String &value)
    9090{
     91    RefPtr<Node> protectFromMutationEvents(this);
     92
    9193    ExceptionCode ec = 0;
    9294    int numChildren = childNodeCount();
    … …  
    9496    if (numChildren == 1 && firstChild()->isTextNode())
    9597        toText(firstChild())->setData(value, ec);
    96     else { 
     98    else {
    9799        // We make a copy here because entity of "value" argument can be Document::m_title,
    98100        // which goes empty during removeChildren() invocation below,
Note: See TracChangeset for help on using the changeset viewer.