Skip to content

Commit d5029c9

Browse files
committed
changes based on review
1 parent a7f733a commit d5029c9

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

python/ql/lib/semmle/python/Concepts.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,8 @@ module RegexExecution {
422422
}
423423

424424
/**
425-
* A node that is not a regular expression literal, but is used in places that
426-
* may interpret it as one. Instances of this class are typically strings that
427-
* flow to method calls like `re.compile`.
425+
* A node where a string is interpreted as a regular expression,
426+
* for instance an argument to `re.compile`.
428427
*
429428
* Extend this class to refine existing API models. If you want to model new APIs,
430429
* extend `RegExpInterpretation::Range` instead.
@@ -434,9 +433,8 @@ class RegExpInterpretation extends DataFlow::Node instanceof RegExpInterpretatio
434433
/** Provides a class for modeling regular expression interpretations. */
435434
module RegExpInterpretation {
436435
/**
437-
* A node that is not a regular expression literal, but is used in places that
438-
* may interpret it as one. Instances of this class are typically strings that
439-
* flow to method calls like `re.compile`.
436+
* A node where a string is interpreted as a regular expression,
437+
* for instance an argument to `re.compile`.
440438
*/
441439
abstract class Range extends DataFlow::Node { }
442440
}

python/ql/lib/semmle/python/dataflow/new/Regexp.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ deprecated module RegExpPatterns {
2626
* as a part of a regular expression.
2727
*/
2828
class RegExpPatternSource extends DataFlow::CfgNode {
29-
private DataFlow::Node sink;
29+
private RegExpSink sink;
3030

3131
RegExpPatternSource() { this = regExpSource(sink) }
3232

3333
/**
3434
* Gets a node where the pattern of this node is parsed as a part of
3535
* a regular expression.
3636
*/
37-
DataFlow::Node getAParse() { result = sink }
37+
RegExpSink getAParse() { result = sink }
3838

3939
/**
4040
* Gets the root term of the regular expression parsed from this pattern.

python/ql/lib/semmle/python/regexp/RegexTreeView.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ module Impl implements RegexTreeViewSig {
525525
*/
526526
private predicate isUnicode() { this.getText().prefix(2) = ["\\u", "\\U"] }
527527

528+
/**
529+
* Gets the unicode char for this escape.
530+
* E.g. for `\u0061` this returns "a".
531+
*/
528532
private string getUnicode() {
529533
result = Numbers::parseHexInt(this.getText().suffix(2)).toUnicode()
530534
}

python/ql/lib/semmle/python/regexp/internal/ParseRegExp.qll

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ private module FindRegexMode {
2626
call.getArg(_) = sink and
2727
sink instanceof Concepts::RegExpInterpretation::Range
2828
|
29-
exists(DataFlow::CallCfgNode callNode |
30-
call = callNode and
31-
result =
32-
mode_from_node([
33-
callNode
34-
.getArg(re_member_flags_arg(callNode.(DataFlow::MethodCallNode).getMethodName())),
35-
callNode.getArgByName("flags")
36-
])
37-
)
29+
result =
30+
mode_from_node([
31+
call.getArg(re_member_flags_arg(call.(DataFlow::MethodCallNode).getMethodName())),
32+
call.getArgByName("flags")
33+
])
3834
)
3935
)
4036
}

python/ql/lib/semmle/python/regexp/internal/RegExpTracking.qll

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ DataFlow::LocalSourceNode strStart() { result.asExpr() instanceof StrConst }
1919

2020
private import semmle.python.regex as Regex
2121

22-
/** Gets a node where regular expressions that flow to the node are used. */
23-
DataFlow::Node regSink() {
24-
result = any(Concepts::RegexExecution exec).getRegex()
25-
or
26-
result instanceof Concepts::RegExpInterpretation
22+
/** A node where regular expressions that flow to the node are used. */
23+
class RegExpSink extends DataFlow::Node {
24+
RegExpSink() {
25+
this = any(Concepts::RegexExecution exec).getRegex()
26+
or
27+
this instanceof Concepts::RegExpInterpretation
28+
}
2729
}
2830

2931
/**
@@ -32,7 +34,7 @@ DataFlow::Node regSink() {
3234
*/
3335
private DataFlow::TypeTrackingNode backwards(DataFlow::TypeBackTracker t) {
3436
t.start() and
35-
result = regSink().getALocalSource()
37+
result = any(RegExpSink sink).getALocalSource()
3638
or
3739
exists(DataFlow::TypeBackTracker t2 | result = backwards(t2).backtrack(t2, t))
3840
}
@@ -69,7 +71,6 @@ private DataFlow::TypeTrackingNode regexTracking(DataFlow::Node start, DataFlow:
6971

7072
/** Gets a node holding a value for the regular expression that is evaluated at `re`. */
7173
cached
72-
DataFlow::Node regExpSource(DataFlow::Node re) {
73-
re = regSink() and
74+
DataFlow::Node regExpSource(RegExpSink re) {
7475
regexTracking(result, DataFlow::TypeTracker::end()).flowsTo(re)
7576
}

0 commit comments

Comments
 (0)