Skip to content

Commit c289f66

Browse files
authored
Merge pull request #13469 from erik-krogh/redos-3.10
ReDoS: stop spuriously matching everything when encountering an unsupported charclass
2 parents 2212440 + 087e6d1 commit c289f66

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

shared/regex/codeql/regex/nfa/NfaUtils.qll

+12-2
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,15 @@ module Make<RegexTreeViewSig TreeImpl> {
451451
}
452452

453453
bindingset[char]
454-
override predicate matches(string char) { not hasChildThatMatches(cc, char) }
454+
override predicate matches(string char) {
455+
not hasChildThatMatches(cc, char) and
456+
(
457+
// detect unsupported char classes that doesn't match anything (e.g. `\p{L}` in ruby), and don't report any matches
458+
hasChildThatMatches(cc, _)
459+
or
460+
not exists(cc.getAChild()) // [^] still matches everything
461+
)
462+
}
455463
}
456464

457465
/**
@@ -536,7 +544,9 @@ module Make<RegexTreeViewSig TreeImpl> {
536544

537545
bindingset[char]
538546
override predicate matches(string char) {
539-
not classEscapeMatches(charClass.toLowerCase(), char)
547+
not classEscapeMatches(charClass.toLowerCase(), char) and
548+
// detect unsupported char classes (e.g. `\p{L}` in ruby), and don't report any matches
549+
classEscapeMatches(charClass.toLowerCase(), _)
540550
}
541551
}
542552

0 commit comments

Comments
 (0)