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

Unified Diff: test/fuzzer/fuzzer.cc

Issue 1604203002: Add a library suitable for libfuzzer with a small unit test runner shell (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 11 months 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 | « test/fuzzer/DEPS ('k') | test/fuzzer/fuzzer.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/fuzzer/fuzzer.cc
diff --git a/test/fuzzer/fuzzer.cc b/test/fuzzer/fuzzer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..71a26b86b379eb428a63ae1063b9b352edf5c01f
--- /dev/null
+++ b/test/fuzzer/fuzzer.cc
@@ -0,0 +1,56 @@
+// Copyright 2016 the V8 project 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 <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv);
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
+
+int main(int argc, char* argv[]) {
+ if (LLVMFuzzerInitialize(&argc, &argv)) {
+ fprintf(stderr, "Failed to initialize fuzzer target\n");
+ return 1;
+ }
+
+ if (argc < 2) {
+ fprintf(stderr, "USAGE: %s <input>\n", argv[0]);
+ return 1;
+ }
+
+ FILE* input = fopen(argv[1], "rb");
+
+ if (!input) {
+ fprintf(stderr, "Failed to open '%s'\n", argv[1]);
+ return 1;
+ }
+
+ fseek(input, 0, SEEK_END);
+ long size = ftell(input);
+ fseek(input, 0, SEEK_SET);
+
+ uint8_t* data = reinterpret_cast<uint8_t*>(malloc(size));
+ if (!data) {
+ fclose(input);
+ fprintf(stderr, "Failed to allocate %ld bytes\n", size);
+ return 1;
+ }
+
+ size_t bytes_read = fread(data, 1, size, input);
+ fclose(input);
+
+ if (bytes_read != size) {
+ free(data);
+ fprintf(stderr, "Failed to read %s\n", argv[1]);
+ return 1;
+ }
+
+ int result = LLVMFuzzerTestOneInput(data, size);
+
+ free(data);
+
+ return result;
+}
« no previous file with comments | « test/fuzzer/DEPS ('k') | test/fuzzer/fuzzer.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698