Skip to content

Commit 9bc12ed

Browse files
committed
sync review changes to other languages
1 parent 28ac476 commit 9bc12ed

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

java/ql/lib/semmle/code/java/security/regexp/NfaUtils.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
890890
*/
891891
private predicate isReDoSCandidate(State state, string pump) {
892892
isCandidate(state, pump) and
893-
not epsilonSucc*(state) = AcceptAnySuffix(_) and // pruning early - these can never get stuck in a rejecting state.
893+
not state = acceptsAnySuffix() and // pruning early - these can never get stuck in a rejecting state.
894894
(
895895
not isCandidate(epsilonSucc+(state), _)
896896
or
@@ -907,6 +907,9 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
907907
)
908908
}
909909

910+
/** Gets a state that can reach the `accept-any` state using only epsilon steps. */
911+
private State acceptsAnySuffix() { epsilonSucc*(result) = AcceptAnySuffix(_) }
912+
910913
/**
911914
* Predicates for constructing a prefix string that leads to a given state.
912915
*/
@@ -1148,9 +1151,6 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
11481151
)
11491152
}
11501153

1151-
/** Gets a state that can reach the `accept-any` state using only epsilon steps. */
1152-
private State acceptsAnySuffix() { epsilonSucc*(result) = AcceptAnySuffix(_) }
1153-
11541154
/**
11551155
* Gets a state that can be reached from pumpable `fork` consuming all
11561156
* chars in `w` any number of times followed by the first `i` characters of `w`.
@@ -1243,8 +1243,8 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
12431243
}
12441244

12451245
/**
1246-
* A module that describes a tree where each node has one or more accosiated characters.
1247-
* The root node has no accosiated character.
1246+
* A module that describes a tree where each node has one or more associated characters, also known as a trie.
1247+
* The root node has no associated character.
12481248
* This module is a signature used in `Concretizer`.
12491249
*/
12501250
signature module CharTree {
@@ -1256,7 +1256,7 @@ signature module CharTree {
12561256

12571257
/**
12581258
* Holds if `n` is at the end of a tree. I.e. a node that should have a result in the `Concretizer` module.
1259-
* A leaf can still have children.
1259+
* Such a node can still have children.
12601260
*/
12611261
predicate isARelevantEnd(CharNode n);
12621262

@@ -1291,32 +1291,33 @@ module Concretizer<CharTree Impl> {
12911291
private predicate isRoot(Node n) { not exists(getPrev(n)) }
12921292

12931293
/** Gets the distance from a root to `n`. */
1294-
private int nodeDist(Node n) {
1294+
private int nodeDepth(Node n) {
12951295
result = 0 and isRoot(n)
12961296
or
12971297
isRelevant(n) and
1298-
exists(Node prev | result = nodeDist(prev) + 1 | prev = getPrev(n))
1298+
exists(Node prev | result = nodeDepth(prev) + 1 | prev = getPrev(n))
12991299
}
13001300

1301-
/** Holds if `n` is part of a chain that we want to compute a string for. */
1301+
/** Gets an ancestor of `end`, where `end` is a node that should have a result in `concretize`. */
13021302
private Node getANodeInLongChain(Node end) {
13031303
isARelevantEnd(end) and result = end
13041304
or
13051305
exists(Node prev | prev = getANodeInLongChain(end) | result = getPrev(prev))
13061306
}
13071307

1308+
/** Gets the `i`th character on the path from the root to `n`. */
13081309
pragma[noinline]
13091310
private string getPrefixChar(Node n, int i) {
13101311
exists(Node prev |
13111312
result = getChar(prev) and
13121313
prev = getANodeInLongChain(n) and
1313-
i = nodeDist(n) - nodeDist(prev)
1314+
i = nodeDepth(prev)
13141315
)
13151316
}
13161317

13171318
/** Gets a string corresponding to `node`. */
13181319
language[monotonicAggregates]
13191320
string concretize(Node n) {
1320-
result = strictconcat(int i | exists(getPrefixChar(n, i)) | getPrefixChar(n, i) order by i desc)
1321+
result = strictconcat(int i | exists(getPrefixChar(n, i)) | getPrefixChar(n, i) order by i)
13211322
}
13221323
}

python/ql/lib/semmle/python/security/regexp/NfaUtils.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
890890
*/
891891
private predicate isReDoSCandidate(State state, string pump) {
892892
isCandidate(state, pump) and
893-
not epsilonSucc*(state) = AcceptAnySuffix(_) and // pruning early - these can never get stuck in a rejecting state.
893+
not state = acceptsAnySuffix() and // pruning early - these can never get stuck in a rejecting state.
894894
(
895895
not isCandidate(epsilonSucc+(state), _)
896896
or
@@ -907,6 +907,9 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
907907
)
908908
}
909909

910+
/** Gets a state that can reach the `accept-any` state using only epsilon steps. */
911+
private State acceptsAnySuffix() { epsilonSucc*(result) = AcceptAnySuffix(_) }
912+
910913
/**
911914
* Predicates for constructing a prefix string that leads to a given state.
912915
*/
@@ -1148,9 +1151,6 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
11481151
)
11491152
}
11501153

1151-
/** Gets a state that can reach the `accept-any` state using only epsilon steps. */
1152-
private State acceptsAnySuffix() { epsilonSucc*(result) = AcceptAnySuffix(_) }
1153-
11541154
/**
11551155
* Gets a state that can be reached from pumpable `fork` consuming all
11561156
* chars in `w` any number of times followed by the first `i` characters of `w`.
@@ -1243,8 +1243,8 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
12431243
}
12441244

12451245
/**
1246-
* A module that describes a tree where each node has one or more accosiated characters.
1247-
* The root node has no accosiated character.
1246+
* A module that describes a tree where each node has one or more associated characters, also known as a trie.
1247+
* The root node has no associated character.
12481248
* This module is a signature used in `Concretizer`.
12491249
*/
12501250
signature module CharTree {
@@ -1256,7 +1256,7 @@ signature module CharTree {
12561256

12571257
/**
12581258
* Holds if `n` is at the end of a tree. I.e. a node that should have a result in the `Concretizer` module.
1259-
* A leaf can still have children.
1259+
* Such a node can still have children.
12601260
*/
12611261
predicate isARelevantEnd(CharNode n);
12621262

@@ -1291,32 +1291,33 @@ module Concretizer<CharTree Impl> {
12911291
private predicate isRoot(Node n) { not exists(getPrev(n)) }
12921292

12931293
/** Gets the distance from a root to `n`. */
1294-
private int nodeDist(Node n) {
1294+
private int nodeDepth(Node n) {
12951295
result = 0 and isRoot(n)
12961296
or
12971297
isRelevant(n) and
1298-
exists(Node prev | result = nodeDist(prev) + 1 | prev = getPrev(n))
1298+
exists(Node prev | result = nodeDepth(prev) + 1 | prev = getPrev(n))
12991299
}
13001300

1301-
/** Holds if `n` is part of a chain that we want to compute a string for. */
1301+
/** Gets an ancestor of `end`, where `end` is a node that should have a result in `concretize`. */
13021302
private Node getANodeInLongChain(Node end) {
13031303
isARelevantEnd(end) and result = end
13041304
or
13051305
exists(Node prev | prev = getANodeInLongChain(end) | result = getPrev(prev))
13061306
}
13071307

1308+
/** Gets the `i`th character on the path from the root to `n`. */
13081309
pragma[noinline]
13091310
private string getPrefixChar(Node n, int i) {
13101311
exists(Node prev |
13111312
result = getChar(prev) and
13121313
prev = getANodeInLongChain(n) and
1313-
i = nodeDist(n) - nodeDist(prev)
1314+
i = nodeDepth(prev)
13141315
)
13151316
}
13161317

13171318
/** Gets a string corresponding to `node`. */
13181319
language[monotonicAggregates]
13191320
string concretize(Node n) {
1320-
result = strictconcat(int i | exists(getPrefixChar(n, i)) | getPrefixChar(n, i) order by i desc)
1321+
result = strictconcat(int i | exists(getPrefixChar(n, i)) | getPrefixChar(n, i) order by i)
13211322
}
13221323
}

python/ql/lib/semmle/python/security/regexp/RegexpMatching.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RootTerm extends RegExpTerm {
1111
}
1212

1313
/**
14-
* Holds if it should be tested whether `reg` matches `str`.
14+
* Holds if it should be tested whether `root` matches `str`.
1515
*
1616
* If `ignorePrefix` is true, then a regexp without a start anchor will be treated as if it had a start anchor.
1717
* E.g. a regular expression `/foo$/` will match any string that ends with "foo",

ruby/ql/lib/codeql/ruby/security/regexp/NfaUtils.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
890890
*/
891891
private predicate isReDoSCandidate(State state, string pump) {
892892
isCandidate(state, pump) and
893-
not epsilonSucc*(state) = AcceptAnySuffix(_) and // pruning early - these can never get stuck in a rejecting state.
893+
not state = acceptsAnySuffix() and // pruning early - these can never get stuck in a rejecting state.
894894
(
895895
not isCandidate(epsilonSucc+(state), _)
896896
or
@@ -907,6 +907,9 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
907907
)
908908
}
909909

910+
/** Gets a state that can reach the `accept-any` state using only epsilon steps. */
911+
private State acceptsAnySuffix() { epsilonSucc*(result) = AcceptAnySuffix(_) }
912+
910913
/**
911914
* Predicates for constructing a prefix string that leads to a given state.
912915
*/
@@ -1148,9 +1151,6 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
11481151
)
11491152
}
11501153

1151-
/** Gets a state that can reach the `accept-any` state using only epsilon steps. */
1152-
private State acceptsAnySuffix() { epsilonSucc*(result) = AcceptAnySuffix(_) }
1153-
11541154
/**
11551155
* Gets a state that can be reached from pumpable `fork` consuming all
11561156
* chars in `w` any number of times followed by the first `i` characters of `w`.
@@ -1243,8 +1243,8 @@ module ReDoSPruning<isCandidateSig/2 isCandidate> {
12431243
}
12441244

12451245
/**
1246-
* A module that describes a tree where each node has one or more accosiated characters.
1247-
* The root node has no accosiated character.
1246+
* A module that describes a tree where each node has one or more associated characters, also known as a trie.
1247+
* The root node has no associated character.
12481248
* This module is a signature used in `Concretizer`.
12491249
*/
12501250
signature module CharTree {
@@ -1256,7 +1256,7 @@ signature module CharTree {
12561256

12571257
/**
12581258
* Holds if `n` is at the end of a tree. I.e. a node that should have a result in the `Concretizer` module.
1259-
* A leaf can still have children.
1259+
* Such a node can still have children.
12601260
*/
12611261
predicate isARelevantEnd(CharNode n);
12621262

@@ -1291,32 +1291,33 @@ module Concretizer<CharTree Impl> {
12911291
private predicate isRoot(Node n) { not exists(getPrev(n)) }
12921292

12931293
/** Gets the distance from a root to `n`. */
1294-
private int nodeDist(Node n) {
1294+
private int nodeDepth(Node n) {
12951295
result = 0 and isRoot(n)
12961296
or
12971297
isRelevant(n) and
1298-
exists(Node prev | result = nodeDist(prev) + 1 | prev = getPrev(n))
1298+
exists(Node prev | result = nodeDepth(prev) + 1 | prev = getPrev(n))
12991299
}
13001300

1301-
/** Holds if `n` is part of a chain that we want to compute a string for. */
1301+
/** Gets an ancestor of `end`, where `end` is a node that should have a result in `concretize`. */
13021302
private Node getANodeInLongChain(Node end) {
13031303
isARelevantEnd(end) and result = end
13041304
or
13051305
exists(Node prev | prev = getANodeInLongChain(end) | result = getPrev(prev))
13061306
}
13071307

1308+
/** Gets the `i`th character on the path from the root to `n`. */
13081309
pragma[noinline]
13091310
private string getPrefixChar(Node n, int i) {
13101311
exists(Node prev |
13111312
result = getChar(prev) and
13121313
prev = getANodeInLongChain(n) and
1313-
i = nodeDist(n) - nodeDist(prev)
1314+
i = nodeDepth(prev)
13141315
)
13151316
}
13161317

13171318
/** Gets a string corresponding to `node`. */
13181319
language[monotonicAggregates]
13191320
string concretize(Node n) {
1320-
result = strictconcat(int i | exists(getPrefixChar(n, i)) | getPrefixChar(n, i) order by i desc)
1321+
result = strictconcat(int i | exists(getPrefixChar(n, i)) | getPrefixChar(n, i) order by i)
13211322
}
13221323
}

ruby/ql/lib/codeql/ruby/security/regexp/RegexpMatching.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RootTerm extends RegExpTerm {
1111
}
1212

1313
/**
14-
* Holds if it should be tested whether `reg` matches `str`.
14+
* Holds if it should be tested whether `root` matches `str`.
1515
*
1616
* If `ignorePrefix` is true, then a regexp without a start anchor will be treated as if it had a start anchor.
1717
* E.g. a regular expression `/foo$/` will match any string that ends with "foo",

0 commit comments

Comments
 (0)