Skip to content

Commit 66a8618

Browse files
committed
Fixed a bug where variables were being wrongly removed
1 parent 2edf210 commit 66a8618

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

framework/codemodder-base/src/main/java/io/codemodder/ast/ASTs.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ public static Optional<MethodCallExpr> isScopeInMethodCall(final Expression expr
182182
}
183183

184184
/**
185-
* Test for this pattern: {@link PatternExpr} ({@code node}) -&gt; {@link SimpleName}
185+
* Test for this pattern: {@link TypePatternExpr} ({@code node}) -&gt; {@link SimpleName}
186186
*
187187
* @return A tuple with the above pattern in order sans the {@link SimpleName}.
188188
*/
189-
public static Optional<PatternExpr> isPatternExprDeclarationOf(
189+
public static Optional<TypePatternExpr> isPatternExprDeclarationOf(
190190
final Node node, final String name) {
191-
if (node instanceof PatternExpr) {
192-
var pexpr = (PatternExpr) node;
191+
if (node instanceof TypePatternExpr) {
192+
var pexpr = (TypePatternExpr) node;
193193
if (pexpr.getNameAsString().equals(name)) return Optional.of(pexpr);
194194
}
195195
return Optional.empty();

framework/codemodder-base/src/main/java/io/codemodder/remediation/sqlinjection/SQLParameterizer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,12 @@ private MethodCallExpr fixByHijackedStatement(
692692
topStatement = gatherAndSetParameters(pStmtName, topStatement, queryParameterizer);
693693

694694
// Add PreparedStmt stmt = conn.prepareStatement() assignment
695+
// Need to clone the nodes in the arguments to make sure the parent node is properly set
695696
MethodCallExpr prepareStatementCall =
696-
new MethodCallExpr(new NameExpr(connName), "prepareStatement", executeCall.getArguments());
697+
new MethodCallExpr(
698+
new NameExpr(connName),
699+
"prepareStatement",
700+
new NodeList<>(executeCall.getArguments().stream().map(n -> n.clone()).toList()));
697701
ExpressionStmt pStmtCreation =
698702
new ExpressionStmt(
699703
new VariableDeclarationExpr(

framework/codemodder-base/src/main/java/io/codemodder/remediation/sqlinjection/SQLParameterizerWithCleanup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void cleanup(final MethodCallExpr pstmtCall) {
2020
// Remove concatenation with empty strings e.g "first" + "" -> "first";
2121
maybeMethodDecl.ifPresent(ASTTransforms::removeEmptyStringConcatenation);
2222
// Remove potential unused variables left after transform
23-
// maybeMethodDecl.ifPresent(md -> ASTTransforms.removeUnusedLocalVariables(md));
23+
maybeMethodDecl.ifPresent(md -> ASTTransforms.removeUnusedLocalVariables(md));
2424

2525
// Merge concatenated literals, e.g. "first" + " and second" -> "first and second"
2626
pstmtCall.getArguments().getFirst().ifPresent(ASTTransforms::mergeConcatenatedLiterals);

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
auto-value = "1.9"
33
jackson = "2.13.1"
4-
javaparser-core = "3.25.4"
4+
javaparser-core = "3.26.2"
55
javaparser-symbolsolver = "3.15.15"
66
java-security-toolkit = "1.2.0"
77
java-security-toolkit-xstream = "1.0.2"

0 commit comments

Comments
 (0)