@@ -4,8 +4,13 @@ private import semmle.code.java.regex.RegexTreeView::RegexTreeView as TreeView
4
4
import codeql.regex.nfa.ExponentialBackTracking:: Make< TreeView > as ExponentialBackTracking
5
5
import semmle.code.java.regex.regex
6
6
7
+ bindingset [ s]
8
+ string quote ( string s ) { if s .matches ( "% %" ) then result = "\"" + s + "\"" else result = s }
9
+
7
10
module HasExpRedos implements TestSig {
8
- string getARelevantTag ( ) { result = [ "hasExpRedos" , "hasParseFailure" ] }
11
+ string getARelevantTag ( ) {
12
+ result = [ "hasExpRedos" , "hasParseFailure" , "hasPump" , "hasPrefixMsg" ]
13
+ }
9
14
10
15
predicate hasActualResult ( Location location , string element , string tag , string value ) {
11
16
tag = "hasExpRedos" and
@@ -25,6 +30,22 @@ module HasExpRedos implements TestSig {
25
30
element = r .toString ( )
26
31
)
27
32
}
33
+
34
+ predicate hasOptionalResult ( Location location , string element , string tag , string value ) {
35
+ exists ( TreeView:: RegExpTerm t , Regex r , string pump , string prefixMsg |
36
+ ExponentialBackTracking:: hasReDoSResult ( t , pump , _, prefixMsg ) and
37
+ t .occursInRegex ( r , _, _) and
38
+ (
39
+ tag = "hasPrefixMsg" and
40
+ value = quote ( prefixMsg )
41
+ or
42
+ tag = "hasPump" and
43
+ value = pump
44
+ ) and
45
+ location = r .getLocation ( ) and
46
+ element = r .toString ( )
47
+ )
48
+ }
28
49
}
29
50
30
51
import MakeTest< HasExpRedos >
0 commit comments