Skip to content

Commit 148a9ab

Browse files
committed
Fix sql injection
1 parent 7be2968 commit 148a9ab

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
cd $CHECKOUT_DIR/
4343
$GITHUB_WORKSPACE/$CIFUZZ_INSTALL_DIR/bin/cifuzz bundle \
4444
--commit $GITHUB_SHA \
45-
--branch $GITHUB_REF_NAME \
45+
--branch $GITHUB_HEAD_REF \
4646
--output $GITHUB_WORKSPACE/$CHECKOUT_DIR/$FUZZING_ARTIFACT
4747
shell: "bash"
4848
- id: start-fuzzing

cifuzz.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
## See https://llvm.org/docs/LibFuzzer.html#options
2525
engine-args:
2626
- --instrumentation_includes=com.example.**
27+
- -rss_limit_mb=8192
2728

2829
## Maximum time to run fuzz tests. The default is to run indefinitely.
2930
#timeout: 30m

src/main/java/com/example/app/controller/GreetEndpointController.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.web.bind.annotation.RestController;
77

88
import java.sql.Connection;
9+
import java.sql.PreparedStatement;
910
import java.sql.SQLException;
1011

1112
@RestController
@@ -16,11 +17,13 @@ public String greet(@RequestParam(required = false, defaultValue = "World") Stri
1617
try {
1718
Connection conn = getDBConnection();
1819
if (conn != null) {
19-
String query = String.format("INSERT INTO users (name) VALUES ('%s')", name);
20-
conn.createStatement().execute(query);
20+
PreparedStatement stmt = conn.prepareStatement("INSERT INTO users (name) VALUES (?)");
21+
stmt.setString(1, name);
22+
stmt.executeUpdate();
2123
conn.close();
2224
}
23-
} catch (SQLException ignored) {}
25+
} catch (SQLException ignored) {
26+
}
2427
}
2528

2629
return "Greetings " + name + "!";

0 commit comments

Comments
 (0)