Skip to content

Commit 1e290b4

Browse files
committed
Swift: Add REDOS analysis to the library test.
1 parent d4c3e9e commit 1e290b4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • swift/ql/test/library-tests/regex

swift/ql/test/library-tests/regex/regex.ql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import swift
22
import codeql.swift.regex.Regex
3+
private import codeql.swift.regex.RegexTreeView::RegexTreeView as TreeView
4+
import codeql.regex.nfa.ExponentialBackTracking::Make<TreeView>
35
import TestUtilities.InlineExpectationsTest
46

57
bindingset[s]
68
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
79

810
module RegexTest implements TestSig {
9-
string getARelevantTag() { result = ["regex", "input"] }
11+
string getARelevantTag() { result = ["regex", "input", "redos-vulnerable"] }
1012

1113
predicate hasActualResult(Location location, string element, string tag, string value) {
1214
exists(RegexEval eval, Expr regex |
@@ -24,6 +26,14 @@ module RegexTest implements TestSig {
2426
tag = "input" and
2527
value = quote(input.toString())
2628
)
29+
or
30+
exists(TreeView::RegExpTerm t, string pump, State s, string prefixMsg |
31+
hasReDoSResult(t, pump, s, prefixMsg) and
32+
location = t.getLocation() and
33+
element = t.toString() and
34+
tag = "redos-vulnerable" and
35+
value = ""
36+
)
2737
}
2838
}
2939

0 commit comments

Comments
 (0)