Skip to content

Commit 9ecc3a2

Browse files
committed
filter out potential misparses from java/suspicious-regexp-range
1 parent 2e295e4 commit 9ecc3a2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

java/ql/src/Security/CWE/CWE-020/SuspiciousRegexpRange.ql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
import semmle.code.java.security.SuspiciousRegexpRangeQuery
1515

16+
RegExpCharacterClass potentialMisparsedCharClass() {
17+
// nested char classes are currently misparsed
18+
result.getAChild().(RegExpNormalChar).getValue() = "["
19+
}
20+
1621
from RegExpCharacterRange range, string reason
17-
where problem(range, reason)
22+
where
23+
problem(range, reason) and
24+
not range.getParent() = potentialMisparsedCharClass()
1825
select range, "Suspicious character range that " + reason + "."

java/ql/test/query-tests/security/CWE-020/SuspiciousRegexpRange.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ void test() {
2929
Pattern overlapsWithClass1 = Pattern.compile("[0-9\\d]*"); // NOT OK
3030

3131
Pattern overlapsWithClass2 = Pattern.compile("[\\w,.-?:*+]*"); // NOT OK
32+
33+
Pattern nested = Pattern.compile("[[A-Za-z_][A-Za-z0-9._-]]*"); // OK, the dash it at the end
34+
35+
Pattern octal = Pattern.compile("[\000-\037\040-\045]*"); // OK
3236
}
3337
}

0 commit comments

Comments
 (0)