@@ -4,8 +4,13 @@ private import semmle.code.java.regex.RegexTreeView::RegexTreeView as TreeView
44import codeql.regex.nfa.ExponentialBackTracking:: Make< TreeView > as ExponentialBackTracking
55import semmle.code.java.regex.regex
66
7+ bindingset [ s]
8+ string quote ( string s ) { if s .matches ( "% %" ) then result = "\"" + s + "\"" else result = s }
9+
710module HasExpRedos implements TestSig {
8- string getARelevantTag ( ) { result = [ "hasExpRedos" , "hasParseFailure" ] }
11+ string getARelevantTag ( ) {
12+ result = [ "hasExpRedos" , "hasParseFailure" , "hasPump" , "hasPrefixMsg" ]
13+ }
914
1015 predicate hasActualResult ( Location location , string element , string tag , string value ) {
1116 tag = "hasExpRedos" and
@@ -25,6 +30,22 @@ module HasExpRedos implements TestSig {
2530 element = r .toString ( )
2631 )
2732 }
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+ }
2849}
2950
3051import MakeTest< HasExpRedos >
0 commit comments