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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv);
11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
12
13
14 int main(int argc, char* argv[]) {
15 if (LLVMFuzzerInitialize(&argc, &argv)) {
16 fprintf(stderr, "Failed to initialize fuzzer target\n");
17 return 1;
18 }
19
20 if (argc != 2) {
21 fprintf(stderr, "USAGE: %s <input>\n", argv[0]);
22 return 1;
23 }
24
25 FILE* input = fopen(argv[1], "rb");
26
27 if (!input) {
28 fprintf(stderr, "Failed to open '%s'\n", argv[1]);
29 return 1;
30 }
31
32 fseek(input, 0, SEEK_END);
33 long size = ftell(input);
34 fseek(input, 0, SEEK_SET);
35
36 uint8_t* data = reinterpret_cast<uint8_t*>(malloc(size));
37 if (!data) {
38 fclose(input);
39 fprintf(stderr, "Failed to allocate %ld bytes\n", size);
40 return 1;
41 }
42
43 fread(data, 1, size, input);
44 fclose(input);
45
46 int result = LLVMFuzzerTestOneInput(data, size);
47
48 free(data);
49
50 return result;
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698