Chromium Code Reviews| Index: testing/libfuzzer/fuzzers/sqlite3_prepare_v2_fuzzer.cc |
| diff --git a/testing/libfuzzer/fuzzers/sqlite3_prepare_v2_fuzzer.cc b/testing/libfuzzer/fuzzers/sqlite3_prepare_v2_fuzzer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d4bb66e0ced0974800e4540cf0542511a1c36ea1 |
| --- /dev/null |
| +++ b/testing/libfuzzer/fuzzers/sqlite3_prepare_v2_fuzzer.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <stddef.h> |
| + |
| +#include "third_party/sqlite/sqlite3.h" |
| + |
| +static int Progress(void *not_used_ptr) { |
| + return 1; |
| +} |
| + |
| +// Entry point for LibFuzzer. |
| +extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) { |
| + if (size < 2) |
| + return 0; |
| + |
| + sqlite3* db; |
| + if (SQLITE_OK != sqlite3_open(":memory:", &db)) |
| + return 0; |
| + |
| + if (data[0] & 1) |
|
aizatsky
2015/12/23 21:04:33
I suggest you add a comment at the top about how y
inferno
2015/12/26 22:33:06
nit: +1 to Mike's comment. I also suggest putting
mmoroz
2016/01/15 19:08:16
Done.
|
| + sqlite3_progress_handler(db, 10000, &Progress, NULL); |
| + else |
| + sqlite3_progress_handler(db, 0, NULL, NULL); |
| + |
| + sqlite3_stmt* statement = NULL; |
| + int r = sqlite3_prepare_v2(db, (const char*)(data + 1), size - 1, |
|
inferno
2015/12/26 22:33:07
s/r/result
mmoroz
2016/01/15 19:08:16
Done.
|
| + &statement, NULL); |
| + if (r == SQLITE_OK) { |
| + for (int i = 0; i < (data[0] >> 1); i++) { |
|
inferno
2015/12/26 22:33:07
What is reason for >> 1, also use the local define
mmoroz
2016/01/15 19:08:16
We used least significant bit above for sqlite3_pr
|
| + if (sqlite3_step(statement) != SQLITE_ROW) |
| + break; |
| + } |
| + |
| + sqlite3_finalize(statement); |
| + } |
| + |
| + sqlite3_close(db); |
| + return 0; |
| +} |