-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new transformation for SQL injection/parameterization codemods (#…
…463) Also adjusts the add statements method to work around some `LexicalPreservingPrinter` issues. This fixed some spacing, indentation issues in some tests.
- Loading branch information
1 parent
d1bfcc9
commit 882f436
Showing
17 changed files
with
400 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,9 +57,9 @@ void foo() { | |
break; | ||
default: | ||
break; | ||
case 0: | ||
break; | ||
} | ||
case 0: | ||
break; | ||
} | ||
} | ||
} | ||
"""; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
core-codemods/src/test/resources/sql-parameterizer/hijackTransformation/Test.java.after
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.acme.testcode; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
public final class Test { | ||
|
||
private Connection conn; | ||
|
||
public void queryAfterDeclaration() throws SQLException { | ||
Statement stmt; | ||
String query2 = "SELECT * FROM users WHERE username = ?"; | ||
PreparedStatement statement = conn.prepareStatement(query2); | ||
statement.setString(1, request.getParameter("username")); | ||
ResultSet rs2 = statement.execute(); | ||
stmt = statement; | ||
while (rs2.next()) { | ||
System.out.println("User: " + rs2.getString("username")); | ||
} | ||
String query3 = "SELECT * FROM users WHERE email = ?"; | ||
stmt.close(); | ||
PreparedStatement stmt1 = conn.prepareStatement(query3); | ||
stmt1.setString(1, request.getParameter("email")); | ||
ResultSet rs3 = stmt1.execute(); | ||
stmt = stmt1; | ||
while (rs3.next()) { | ||
System.out.println("User: " + rs3.getString("username")); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
core-codemods/src/test/resources/sql-parameterizer/hijackTransformation/Test.java.before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.acme.testcode; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
public final class Test { | ||
|
||
private Connection conn; | ||
|
||
public void queryAfterDeclaration() throws SQLException { | ||
Statement stmt = conn.createStatement(); | ||
String username = request.getParameter("username"); | ||
String query2 = "SELECT * FROM users WHERE username = '" + username + "'"; | ||
ResultSet rs2 = stmt.executeQuery(query2); | ||
while (rs2.next()) { | ||
System.out.println("User: " + rs2.getString("username")); | ||
} | ||
String email = request.getParameter("email"); | ||
String query3 = "SELECT * FROM users WHERE email = '" + email + "'"; | ||
ResultSet rs3 = stmt.executeQuery(query3); | ||
while (rs3.next()) { | ||
System.out.println("User: " + rs3.getString("username")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.