Skip to content

Commit 1d56748

Browse files
authored
Merge pull request #6200 from yoff/pythonJS-make-expbtlib-private
Approved by RasmusWL, esbena
2 parents a25933a + 6f26426 commit 1d56748

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

javascript/ql/src/semmle/javascript/security/performance/ExponentialBackTracking.qll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ import ReDoSUtil
6868
* Holds if state `s` might be inside a backtracking repetition.
6969
*/
7070
pragma[noinline]
71-
predicate stateInsideBacktracking(State s) {
71+
private predicate stateInsideBacktracking(State s) {
7272
s.getRepr().getParent*() instanceof MaybeBacktrackingRepetition
7373
}
7474

7575
/**
7676
* A infinitely repeating quantifier that might backtrack.
7777
*/
78-
class MaybeBacktrackingRepetition extends InfiniteRepetitionQuantifier {
78+
private class MaybeBacktrackingRepetition extends InfiniteRepetitionQuantifier {
7979
MaybeBacktrackingRepetition() {
8080
exists(RegExpTerm child |
8181
child instanceof RegExpAlt or
@@ -89,7 +89,7 @@ class MaybeBacktrackingRepetition extends InfiniteRepetitionQuantifier {
8989
/**
9090
* A state in the product automaton.
9191
*/
92-
newtype TStatePair =
92+
private newtype TStatePair =
9393
/**
9494
* We lazily only construct those states that we are actually
9595
* going to need: `(q, q)` for every fork state `q`, and any
@@ -112,7 +112,7 @@ newtype TStatePair =
112112
* Gets a unique number for a `state`.
113113
* Is used to create an ordering of states, where states with the same `toString()` will be ordered differently.
114114
*/
115-
int rankState(State state) {
115+
private int rankState(State state) {
116116
state =
117117
rank[result](State s, Location l |
118118
l = s.getRepr().getLocation()
@@ -124,7 +124,7 @@ int rankState(State state) {
124124
/**
125125
* A state in the product automaton.
126126
*/
127-
class StatePair extends TStatePair {
127+
private class StatePair extends TStatePair {
128128
State q1;
129129
State q2;
130130

@@ -145,21 +145,21 @@ class StatePair extends TStatePair {
145145
*
146146
* Used in `statePairDist`
147147
*/
148-
predicate isStatePair(StatePair p) { any() }
148+
private predicate isStatePair(StatePair p) { any() }
149149

150150
/**
151151
* Holds if there are transitions from the components of `q` to the corresponding
152152
* components of `r`.
153153
*
154154
* Used in `statePairDist`
155155
*/
156-
predicate delta2(StatePair q, StatePair r) { step(q, _, _, r) }
156+
private predicate delta2(StatePair q, StatePair r) { step(q, _, _, r) }
157157

158158
/**
159159
* Gets the minimum length of a path from `q` to `r` in the
160160
* product automaton.
161161
*/
162-
int statePairDist(StatePair q, StatePair r) =
162+
private int statePairDist(StatePair q, StatePair r) =
163163
shortestDistances(isStatePair/1, delta2/2)(q, r, result)
164164

165165
/**
@@ -172,7 +172,7 @@ int statePairDist(StatePair q, StatePair r) =
172172
* expression cannot be vulnerable to ReDoS attacks anyway).
173173
*/
174174
pragma[noopt]
175-
predicate isFork(State q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
175+
private predicate isFork(State q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
176176
stateInsideBacktracking(q) and
177177
exists(State q1, State q2 |
178178
q1 = epsilonSucc*(q) and
@@ -222,15 +222,15 @@ predicate isFork(State q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
222222
* Gets the state pair `(q1, q2)` or `(q2, q1)`; note that only
223223
* one or the other is defined.
224224
*/
225-
StatePair mkStatePair(State q1, State q2) {
225+
private StatePair mkStatePair(State q1, State q2) {
226226
result = MkStatePair(q1, q2) or result = MkStatePair(q2, q1)
227227
}
228228

229229
/**
230230
* Holds if there are transitions from the components of `q` to the corresponding
231231
* components of `r` labelled with `s1` and `s2`, respectively.
232232
*/
233-
predicate step(StatePair q, InputSymbol s1, InputSymbol s2, StatePair r) {
233+
private predicate step(StatePair q, InputSymbol s1, InputSymbol s2, StatePair r) {
234234
exists(State r1, State r2 | step(q, s1, s2, r1, r2) and r = mkStatePair(r1, r2))
235235
}
236236

@@ -242,7 +242,7 @@ predicate step(StatePair q, InputSymbol s1, InputSymbol s2, StatePair r) {
242242
* inside a repetition that might backtrack.
243243
*/
244244
pragma[noopt]
245-
predicate step(StatePair q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
245+
private predicate step(StatePair q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
246246
exists(State q1, State q2 | q.getLeft() = q1 and q.getRight() = q2 |
247247
deltaClosed(q1, s1, r1) and
248248
deltaClosed(q2, s2, r2) and
@@ -268,7 +268,7 @@ private newtype TTrace =
268268
* A list of pairs of input symbols that describe a path in the product automaton
269269
* starting from some fork state.
270270
*/
271-
class Trace extends TTrace {
271+
private class Trace extends TTrace {
272272
/** Gets a textual representation of this element. */
273273
string toString() {
274274
this = Nil() and result = "Nil()"
@@ -282,7 +282,7 @@ class Trace extends TTrace {
282282
/**
283283
* Gets a string corresponding to the trace `t`.
284284
*/
285-
string concretise(Trace t) {
285+
private string concretise(Trace t) {
286286
t = Nil() and result = ""
287287
or
288288
exists(InputSymbol s1, InputSymbol s2, Trace rest | t = Step(s1, s2, rest) |
@@ -294,7 +294,7 @@ string concretise(Trace t) {
294294
* Holds if `r` is reachable from `(fork, fork)` under input `w`, and there is
295295
* a path from `r` back to `(fork, fork)` with `rem` steps.
296296
*/
297-
predicate isReachableFromFork(State fork, StatePair r, Trace w, int rem) {
297+
private predicate isReachableFromFork(State fork, StatePair r, Trace w, int rem) {
298298
// base case
299299
exists(InputSymbol s1, InputSymbol s2, State q1, State q2 |
300300
isFork(fork, s1, s2, q1, q2) and
@@ -316,15 +316,15 @@ predicate isReachableFromFork(State fork, StatePair r, Trace w, int rem) {
316316
* Gets a state in the product automaton from which `(fork, fork)` is
317317
* reachable in zero or more epsilon transitions.
318318
*/
319-
StatePair getAForkPair(State fork) {
319+
private StatePair getAForkPair(State fork) {
320320
isFork(fork, _, _, _, _) and
321321
result = MkStatePair(epsilonPred*(fork), epsilonPred*(fork))
322322
}
323323

324324
/**
325325
* Holds if `fork` is a pumpable fork with word `w`.
326326
*/
327-
predicate isPumpable(State fork, string w) {
327+
private predicate isPumpable(State fork, string w) {
328328
exists(StatePair q, Trace t |
329329
isReachableFromFork(fork, q, t, _) and
330330
q = getAForkPair(fork) and

python/ql/src/semmle/python/security/performance/ExponentialBackTracking.qll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ import ReDoSUtil
6868
* Holds if state `s` might be inside a backtracking repetition.
6969
*/
7070
pragma[noinline]
71-
predicate stateInsideBacktracking(State s) {
71+
private predicate stateInsideBacktracking(State s) {
7272
s.getRepr().getParent*() instanceof MaybeBacktrackingRepetition
7373
}
7474

7575
/**
7676
* A infinitely repeating quantifier that might backtrack.
7777
*/
78-
class MaybeBacktrackingRepetition extends InfiniteRepetitionQuantifier {
78+
private class MaybeBacktrackingRepetition extends InfiniteRepetitionQuantifier {
7979
MaybeBacktrackingRepetition() {
8080
exists(RegExpTerm child |
8181
child instanceof RegExpAlt or
@@ -89,7 +89,7 @@ class MaybeBacktrackingRepetition extends InfiniteRepetitionQuantifier {
8989
/**
9090
* A state in the product automaton.
9191
*/
92-
newtype TStatePair =
92+
private newtype TStatePair =
9393
/**
9494
* We lazily only construct those states that we are actually
9595
* going to need: `(q, q)` for every fork state `q`, and any
@@ -112,7 +112,7 @@ newtype TStatePair =
112112
* Gets a unique number for a `state`.
113113
* Is used to create an ordering of states, where states with the same `toString()` will be ordered differently.
114114
*/
115-
int rankState(State state) {
115+
private int rankState(State state) {
116116
state =
117117
rank[result](State s, Location l |
118118
l = s.getRepr().getLocation()
@@ -124,7 +124,7 @@ int rankState(State state) {
124124
/**
125125
* A state in the product automaton.
126126
*/
127-
class StatePair extends TStatePair {
127+
private class StatePair extends TStatePair {
128128
State q1;
129129
State q2;
130130

@@ -145,21 +145,21 @@ class StatePair extends TStatePair {
145145
*
146146
* Used in `statePairDist`
147147
*/
148-
predicate isStatePair(StatePair p) { any() }
148+
private predicate isStatePair(StatePair p) { any() }
149149

150150
/**
151151
* Holds if there are transitions from the components of `q` to the corresponding
152152
* components of `r`.
153153
*
154154
* Used in `statePairDist`
155155
*/
156-
predicate delta2(StatePair q, StatePair r) { step(q, _, _, r) }
156+
private predicate delta2(StatePair q, StatePair r) { step(q, _, _, r) }
157157

158158
/**
159159
* Gets the minimum length of a path from `q` to `r` in the
160160
* product automaton.
161161
*/
162-
int statePairDist(StatePair q, StatePair r) =
162+
private int statePairDist(StatePair q, StatePair r) =
163163
shortestDistances(isStatePair/1, delta2/2)(q, r, result)
164164

165165
/**
@@ -172,7 +172,7 @@ int statePairDist(StatePair q, StatePair r) =
172172
* expression cannot be vulnerable to ReDoS attacks anyway).
173173
*/
174174
pragma[noopt]
175-
predicate isFork(State q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
175+
private predicate isFork(State q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
176176
stateInsideBacktracking(q) and
177177
exists(State q1, State q2 |
178178
q1 = epsilonSucc*(q) and
@@ -222,15 +222,15 @@ predicate isFork(State q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
222222
* Gets the state pair `(q1, q2)` or `(q2, q1)`; note that only
223223
* one or the other is defined.
224224
*/
225-
StatePair mkStatePair(State q1, State q2) {
225+
private StatePair mkStatePair(State q1, State q2) {
226226
result = MkStatePair(q1, q2) or result = MkStatePair(q2, q1)
227227
}
228228

229229
/**
230230
* Holds if there are transitions from the components of `q` to the corresponding
231231
* components of `r` labelled with `s1` and `s2`, respectively.
232232
*/
233-
predicate step(StatePair q, InputSymbol s1, InputSymbol s2, StatePair r) {
233+
private predicate step(StatePair q, InputSymbol s1, InputSymbol s2, StatePair r) {
234234
exists(State r1, State r2 | step(q, s1, s2, r1, r2) and r = mkStatePair(r1, r2))
235235
}
236236

@@ -242,7 +242,7 @@ predicate step(StatePair q, InputSymbol s1, InputSymbol s2, StatePair r) {
242242
* inside a repetition that might backtrack.
243243
*/
244244
pragma[noopt]
245-
predicate step(StatePair q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
245+
private predicate step(StatePair q, InputSymbol s1, InputSymbol s2, State r1, State r2) {
246246
exists(State q1, State q2 | q.getLeft() = q1 and q.getRight() = q2 |
247247
deltaClosed(q1, s1, r1) and
248248
deltaClosed(q2, s2, r2) and
@@ -268,7 +268,7 @@ private newtype TTrace =
268268
* A list of pairs of input symbols that describe a path in the product automaton
269269
* starting from some fork state.
270270
*/
271-
class Trace extends TTrace {
271+
private class Trace extends TTrace {
272272
/** Gets a textual representation of this element. */
273273
string toString() {
274274
this = Nil() and result = "Nil()"
@@ -282,7 +282,7 @@ class Trace extends TTrace {
282282
/**
283283
* Gets a string corresponding to the trace `t`.
284284
*/
285-
string concretise(Trace t) {
285+
private string concretise(Trace t) {
286286
t = Nil() and result = ""
287287
or
288288
exists(InputSymbol s1, InputSymbol s2, Trace rest | t = Step(s1, s2, rest) |
@@ -294,7 +294,7 @@ string concretise(Trace t) {
294294
* Holds if `r` is reachable from `(fork, fork)` under input `w`, and there is
295295
* a path from `r` back to `(fork, fork)` with `rem` steps.
296296
*/
297-
predicate isReachableFromFork(State fork, StatePair r, Trace w, int rem) {
297+
private predicate isReachableFromFork(State fork, StatePair r, Trace w, int rem) {
298298
// base case
299299
exists(InputSymbol s1, InputSymbol s2, State q1, State q2 |
300300
isFork(fork, s1, s2, q1, q2) and
@@ -316,15 +316,15 @@ predicate isReachableFromFork(State fork, StatePair r, Trace w, int rem) {
316316
* Gets a state in the product automaton from which `(fork, fork)` is
317317
* reachable in zero or more epsilon transitions.
318318
*/
319-
StatePair getAForkPair(State fork) {
319+
private StatePair getAForkPair(State fork) {
320320
isFork(fork, _, _, _, _) and
321321
result = MkStatePair(epsilonPred*(fork), epsilonPred*(fork))
322322
}
323323

324324
/**
325325
* Holds if `fork` is a pumpable fork with word `w`.
326326
*/
327-
predicate isPumpable(State fork, string w) {
327+
private predicate isPumpable(State fork, string w) {
328328
exists(StatePair q, Trace t |
329329
isReachableFromFork(fork, q, t, _) and
330330
q = getAForkPair(fork) and

0 commit comments

Comments
 (0)