Skip to content

Commit 79cd7bf

Browse files
committed
Python: create semmle/python/dataflow/new/Regex.qll
1 parent 9412b33 commit 79cd7bf

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import python
44
private import semmle.python.regex
5-
private import semmle.python.dataflow.new.DataFlow
65

76
/**
87
* An element containing a regular expression term, that is, either
@@ -49,19 +48,6 @@ newtype TRegExpParent =
4948
/** A back reference */
5049
TRegExpBackRef(Regex re, int start, int end) { re.backreference(start, end) }
5150

52-
/**
53-
* Provides utility predicates related to regular expressions.
54-
*/
55-
module RegExpPatterns {
56-
/**
57-
* Gets a pattern that matches common top-level domain names in lower case.
58-
*/
59-
string getACommonTld() {
60-
// according to ranking by http://google.com/search?q=site:.<<TLD>>
61-
result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
62-
}
63-
}
64-
6551
/**
6652
* An element containing a regular expression term, that is, either
6753
* a string literal (parsed as a regular expression)
@@ -1028,24 +1014,3 @@ class RegExpBackRef extends RegExpTerm, TRegExpBackRef {
10281014

10291015
/** Gets the parse tree resulting from parsing `re`, if such has been constructed. */
10301016
RegExpTerm getParsedRegExp(StrConst re) { result.getRegex() = re and result.isRootTerm() }
1031-
1032-
/**
1033-
* A node whose value may flow to a position where it is interpreted
1034-
* as a part of a regular expression.
1035-
*/
1036-
class RegExpPatternSource extends DataFlow::CfgNode {
1037-
private Regex astNode;
1038-
1039-
RegExpPatternSource() { astNode = this.asExpr() }
1040-
1041-
/**
1042-
* Gets a node where the pattern of this node is parsed as a part of
1043-
* a regular expression.
1044-
*/
1045-
DataFlow::Node getAParse() { result = this }
1046-
1047-
/**
1048-
* Gets the root term of the regular expression parsed from this pattern.
1049-
*/
1050-
RegExpTerm getRegExpTerm() { result.getRegex() = astNode }
1051-
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Provides classes for working with regular expressions.
3+
*/
4+
5+
private import semmle.python.RegexTreeView
6+
private import semmle.python.regex
7+
private import semmle.python.dataflow.new.DataFlow
8+
9+
/**
10+
* Provides utility predicates related to regular expressions.
11+
*/
12+
module RegExpPatterns {
13+
/**
14+
* Gets a pattern that matches common top-level domain names in lower case.
15+
*/
16+
string getACommonTld() {
17+
// according to ranking by http://google.com/search?q=site:.<<TLD>>
18+
result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
19+
}
20+
}
21+
22+
/**
23+
* A node whose value may flow to a position where it is interpreted
24+
* as a part of a regular expression.
25+
*/
26+
class RegExpPatternSource extends DataFlow::CfgNode {
27+
private Regex astNode;
28+
29+
RegExpPatternSource() { astNode = this.asExpr() }
30+
31+
/**
32+
* Gets a node where the pattern of this node is parsed as a part of
33+
* a regular expression.
34+
*/
35+
DataFlow::Node getAParse() { result = this }
36+
37+
/**
38+
* Gets the root term of the regular expression parsed from this pattern.
39+
*/
40+
RegExpTerm getRegExpTerm() { result.getRegex() = astNode }
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import semmle.python.security.performance.RegExpTreeView
22
import semmle.python.dataflow.new.DataFlow
3+
import semmle.python.dataflow.new.Regexp

0 commit comments

Comments
 (0)