Skip to content

Commit 29a5b27

Browse files
committed
Removed bounds checking and only using literals - bounded() predicate did not work
1 parent 801cd72 commit 29a5b27

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

java/ql/lib/semmle/code/java/security/SensitiveLoggingQuery.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private class PrefixSuffixBarrier extends SensitiveLoggerBarrier {
5454
exists(MethodCall mc, Method m, int limit |
5555
limit = 7 and
5656
mc.getMethod() = m
57-
|
57+
|
5858
// substring in Java
5959
(
6060
m.hasQualifiedName("java.lang", "String", "substring") or
@@ -86,23 +86,25 @@ private class PrefixSuffixBarrier extends SensitiveLoggerBarrier {
8686
/** A predicate to check single-argument method calls for a constant integer below a set limit. */
8787
bindingset[limit, isKotlin]
8888
private predicate singleArgLimit(MethodCall mc, int limit, boolean isKotlin) {
89-
exists(int argIndex |
90-
(if isKotlin = true then argIndex = 1 else argIndex = 0) and
91-
bounded(mc.getArgument(argIndex), any(ZeroBound z), limit, true, _)
89+
mc.getNumArgument() = 1 and
90+
exists(int firstArgIndex |
91+
(if isKotlin = true then firstArgIndex = 1 else firstArgIndex = 0) and
92+
mc.getArgument(firstArgIndex).getUnderlyingExpr().(CompileTimeConstantExpr).getIntValue() <= limit
9293
)
9394
}
9495

9596
/** A predicate to check two-argument method calls for zero and a constant integer below a set limit. */
9697
bindingset[limit, isKotlin]
9798
private predicate twoArgLimit(MethodCall mc, int limit, boolean isKotlin) {
99+
mc.getNumArgument() = 2 and
98100
exists(int firstArgIndex, int secondArgIndex |
99101
(
100102
isKotlin = true and firstArgIndex = 1 and secondArgIndex = 2
101103
or
102104
isKotlin = false and firstArgIndex = 0 and secondArgIndex = 1
103105
) and
104106
mc.getArgument(firstArgIndex).getUnderlyingExpr().(CompileTimeConstantExpr).getIntValue() = 0 and
105-
bounded(mc.getArgument(secondArgIndex), any(ZeroBound z), limit, true, _)
107+
mc.getArgument(secondArgIndex).getUnderlyingExpr().(CompileTimeConstantExpr).getIntValue() <= limit
106108
)
107109
}
108110

0 commit comments

Comments
 (0)