Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: testing/libfuzzer/fuzzers/sqlite3_prepare_v2_fuzzer.cc

Issue 1549793002: port of sqlite3 fuzzer with some updates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix the nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/libfuzzer/fuzzers/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fda2f84551af9defcd9e1b87a78a98915e249685
--- /dev/null
+++ b/testing/libfuzzer/fuzzers/sqlite3_prepare_v2_fuzzer.cc
@@ -0,0 +1,49 @@
+// 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;
+
+ // Use first byte as random selector for other parameters.
+ int selector = data[0];
kcc2 2016/01/04 19:05:13 Two problems with this approach: 1. Now you can n
mmoroz 2016/01/15 19:08:16 Thanks, 1. Yes, I do remove first byte at line #3
+
+ // To cover both cases when progress_handler is used and isn't used.
+ if (selector & 1)
+ sqlite3_progress_handler(db, 4, &Progress, NULL);
+ else
+ sqlite3_progress_handler(db, 0, NULL, NULL);
+
+ // Remove least significant bit to make further usage of selector independent.
+ selector <<= 1;
+
+ sqlite3_stmt* statement = NULL;
+ int result = sqlite3_prepare_v2(db, (const char*)(data + 1), size - 1,
+ &statement, NULL);
+ if (result == SQLITE_OK) {
+ // Use selector value to randomize number of iterations.
+ for (int i = 0; i < selector; i++) {
+ if (sqlite3_step(statement) != SQLITE_ROW)
+ break;
+ }
+
+ sqlite3_finalize(statement);
+ }
+
+ sqlite3_close(db);
+ return 0;
+}
« no previous file with comments | « testing/libfuzzer/fuzzers/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698