Skip to content

Commit 3424d8b

Browse files
cleanup
1 parent dc1d1d4 commit 3424d8b

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

java-checks-test-sources/default/src/main/java/checks/SQLInjection.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,17 @@ public void formattedConst(Locale locale, String input) throws SQLException {
286286
String query = "SELECT %s".formatted("1");
287287
this.stmt.execute(query);
288288
}
289+
290+
public void plusAssignment(String input) throws SQLException {
291+
String query = "SELECT";
292+
query += String.format("WHERE col = %c", input);
293+
this.stmt.execute(query); // Noncompliant
294+
}
295+
296+
public void plusAssignmentConst() throws SQLException {
297+
// FP, but probably rare and not worth complicating the code to fix it.
298+
String query = "SELECT";
299+
query += String.format("WHERE col = \"%c\"", "value");
300+
this.stmt.execute(query); // Noncompliant
301+
}
289302
}

java-checks/src/main/java/org/sonar/java/checks/SQLInjectionCheck.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ public List<Tree.Kind> nodesToVisit() {
131131
@Override
132132
public void visitNode(Tree tree) {
133133
if (anyMatch(tree)) {
134-
var dbg = QuickFixHelper.contentForTree(tree, context);
135-
136134
Optional<ExpressionTree> sqlStringArg = arguments(tree)
137135
.filter(arg -> arg.symbolType().is(JAVA_LANG_STRING))
138136
.findFirst();
@@ -208,21 +206,21 @@ private static boolean isDynamicPlusAssignment(ExpressionTree arg) {
208206
return arg.is(Tree.Kind.PLUS_ASSIGNMENT) && !((AssignmentExpressionTree) arg).expression().asConstant().isPresent();
209207
}
210208

211-
private boolean isDynamicString(ExpressionTree arg) {
209+
private static boolean isDynamicString(ExpressionTree arg) {
212210
return isDynamicConcatenation(arg) || isDynamicFormatting(arg);
213211
}
214212

215213
private static boolean isDynamicConcatenation(ExpressionTree arg) {
216214
return arg.is(Tree.Kind.PLUS) && !arg.asConstant().isPresent();
217215
}
218216

219-
private boolean isDynamicFormatting(Tree tree) {
217+
private static boolean isDynamicFormatting(Tree tree) {
220218
return tree instanceof MethodInvocationTree mit
221219
&& FORMAT_METHODS.matches(mit)
222220
&& hasDynamicStringParameters(mit);
223221
}
224222

225-
private boolean hasDynamicStringParameters(MethodInvocationTree mit) {
223+
private static boolean hasDynamicStringParameters(MethodInvocationTree mit) {
226224
for (ExpressionTree arg: mit.arguments()) {
227225
if (arg.symbolType().is(JAVA_LANG_STRING) && arg.asConstant().isEmpty()) {
228226
return true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy