Skip to content

Commit 2b2f342

Browse files
committed
Refactor logInjectionGuard part 1
1 parent 1f2ebf4 commit 2b2f342

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ private predicate logInjectionSanitizer(MethodCall ma) {
9696
* by checking if there are line breaks in `e`.
9797
*/
9898
private predicate logInjectionGuard(Guard g, Expr e, boolean branch) {
99+
exists(MethodCall ma | ma = g |
100+
ma.getMethod() instanceof StringContainsMethod and
101+
ma.getArgument(0).(CompileTimeConstantExpr).getStringValue() = ["\n", "\r"] and
102+
e = ma.getQualifier() and
103+
branch = false
104+
)
105+
or
99106
exists(MethodCall ma, CompileTimeConstantExpr target |
100107
ma = g and
101108
target = ma.getArgument(0)
102109
|
103-
ma.getMethod().getDeclaringType() instanceof TypeString and
104-
ma.getMethod().hasName("contains") and
105-
target.getStringValue() = ["\n", "\r"] and
106-
e = ma.getQualifier() and
107-
branch = false
108-
or
109110
ma.getMethod().hasName("matches") and
110111
(
111112
ma.getMethod().getDeclaringType() instanceof TypeString and

0 commit comments

Comments
 (0)