Skip to content

Commit

Permalink
Cherry-pick 274575@main (3113660). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=269308

    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/266719.372@webkitglib/2.42
  • Loading branch information
szewai authored and aperezdc committed Mar 14, 2024
1 parent e620daf commit 724a0de
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 @@ -1045,17 +1045,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 724a0de

Please sign in to comment.