Skip to content

Commit

Permalink
Cherry-pick 3113660. rdar://122892811
Browse files Browse the repository at this point in the history
    Null pointer dereference in elementHasClassInClosestAncestors
    https://bugs.webkit.org/show_bug.cgi?id=269308
    rdar://122892811

    Reviewed by Brent Fulgham.

    Ensure ancestor is non-null before accessing it.

    * Source/WebCore/page/Quirks.cpp:
    (WebCore::elementHasClassInClosestAncestors):

    Canonical link: https://commits.webkit.org/274575@main

Canonical link: https://commits.webkit.org/272448.566@safari-7618.1.15.10-branch
  • Loading branch information
szewai authored and Dan Robson committed Feb 14, 2024
1 parent 2c392a8 commit c227290
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Source/WebCore/page/Quirks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,17 +1152,14 @@ static bool elementHasClassInClosestAncestors(const Element& element, const Atom
if (element.hasClass() && element.classNames().contains(className))
return true;

unsigned currentDistance = 1;
unsigned currentDistance = 0;
RefPtr ancestor = dynamicDowncast<Element>(element.parentNode());
while (currentDistance <= distance) {
while (ancestor && currentDistance < distance) {
++currentDistance;
if (ancestor->hasClass() && ancestor->classNames().contains(className))
return true;

ancestor = dynamicDowncast<Element>(ancestor->parentNode());
if (!ancestor)
return false;

++currentDistance;
}
return false;
}
Expand Down

0 comments on commit c227290

Please sign in to comment.