Skip to content

Commit c40ffab

Browse files
committed
make isStartState public in ReDoSUtil
1 parent 672e4a3 commit c40ffab

File tree

2 files changed

+20
-26
lines changed
  • javascript/ql/lib/semmle/javascript/security/performance
  • python/ql/lib/semmle/python/security/performance

2 files changed

+20
-26
lines changed

javascript/ql/lib/semmle/javascript/security/performance/ReDoSUtil.qll

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,29 +803,26 @@ InputSymbol getAnInputSymbolMatching(string char) {
803803
result = Any()
804804
}
805805

806+
/**
807+
* Holds if `state` is a start state.
808+
*/
809+
predicate isStartState(State state) {
810+
state = mkMatch(any(RegExpRoot r))
811+
or
812+
exists(RegExpCaret car | state = after(car))
813+
}
814+
806815
/**
807816
* Predicates for constructing a prefix string that leads to a given state.
808817
*/
809818
private module PrefixConstruction {
810-
/**
811-
* Holds if `state` starts the string matched by the regular expression.
812-
*/
813-
private predicate isStartState(State state) {
814-
state instanceof StateInPumpableRegexp and
815-
(
816-
state = Match(any(RegExpRoot r), _)
817-
or
818-
exists(RegExpCaret car | state = after(car))
819-
)
820-
}
821-
822819
/**
823820
* Holds if `state` is the textually last start state for the regular expression.
824821
*/
825822
private predicate lastStartState(State state) {
826823
exists(RegExpRoot root |
827824
state =
828-
max(State s, Location l |
825+
max(StateInPumpableRegexp s, Location l |
829826
isStartState(s) and getRoot(s.getRepr()) = root and l = s.getRepr().getLocation()
830827
|
831828
s

python/ql/lib/semmle/python/security/performance/ReDoSUtil.qll

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,29 +803,26 @@ InputSymbol getAnInputSymbolMatching(string char) {
803803
result = Any()
804804
}
805805

806+
/**
807+
* Holds if `state` is a start state.
808+
*/
809+
predicate isStartState(State state) {
810+
state = mkMatch(any(RegExpRoot r))
811+
or
812+
exists(RegExpCaret car | state = after(car))
813+
}
814+
806815
/**
807816
* Predicates for constructing a prefix string that leads to a given state.
808817
*/
809818
private module PrefixConstruction {
810-
/**
811-
* Holds if `state` starts the string matched by the regular expression.
812-
*/
813-
private predicate isStartState(State state) {
814-
state instanceof StateInPumpableRegexp and
815-
(
816-
state = Match(any(RegExpRoot r), _)
817-
or
818-
exists(RegExpCaret car | state = after(car))
819-
)
820-
}
821-
822819
/**
823820
* Holds if `state` is the textually last start state for the regular expression.
824821
*/
825822
private predicate lastStartState(State state) {
826823
exists(RegExpRoot root |
827824
state =
828-
max(State s, Location l |
825+
max(StateInPumpableRegexp s, Location l |
829826
isStartState(s) and getRoot(s.getRepr()) = root and l = s.getRepr().getLocation()
830827
|
831828
s

0 commit comments

Comments
 (0)