forked from google/oss-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlPreparedStatementFuzzer.java
57 lines (49 loc) · 1.7 KB
/
SqlPreparedStatementFuzzer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh;
import org.h2.tools.Server;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
public class SqlPreparedStatementFuzzer extends TestServer {
SqlPreparedStatementFuzzer(boolean verbose) throws SQLException {
super("myH2DBPassword", verbose);
}
public String getTestName() {
return getClass().getSimpleName();
}
static void testOneInput(String fuzzyString, boolean verbose) {
SqlStatementFuzzer server;
try {
server = new SqlStatementFuzzer(verbose);
} catch (SQLException ex) {
ex.printStackTrace(System.out);
return;
}
try {
Connection connection = server.getConnection();
connection.createStatement().executeUpdate("DROP TABLE IF EXISTS t; CREATE TABLE t (x VARCHAR(255));");
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t(x) VALUES(?)");
preparedStatement.setString(1, fuzzyString);
preparedStatement.executeUpdate();
server.diagnostic("insert performed");
} catch (SQLException ex) {
/* ignore */
server.diagnostic("insert not executed");
server.diagnostic(ex);
}
if ( ! server.isRunning() ) {
throw new FuzzerSecurityIssueHigh("SQL Statement caused server crash");
}
try {
server.stop();
} catch (SQLException ex) {
throw new FuzzerSecurityIssueHigh("Why can't we shutdown the server?");
}
}
public static void fuzzerTestOneInput(FuzzedDataProvider fuzzedDataProvider) {
testOneInput(fuzzedDataProvider.consumeRemainingAsAsciiString(), false);
}
}