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

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: updates Created 4 years, 10 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
« no previous file with comments | « test/fuzzer/DEPS ('k') | test/fuzzer/fuzzer.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 int main(int argc, char* argv[]) {
14 if (LLVMFuzzerInitialize(&argc, &argv)) {
15 fprintf(stderr, "Failed to initialize fuzzer target\n");
16 return 1;
17 }
18
19 if (argc < 2) {
20 fprintf(stderr, "USAGE: %s <input>\n", argv[0]);
21 return 1;
22 }
23
24 FILE* input = fopen(argv[1], "rb");
25
26 if (!input) {
27 fprintf(stderr, "Failed to open '%s'\n", argv[1]);
28 return 1;
29 }
30
31 fseek(input, 0, SEEK_END);
32 long size = ftell(input);
33 fseek(input, 0, SEEK_SET);
34
35 uint8_t* data = reinterpret_cast<uint8_t*>(malloc(size));
36 if (!data) {
37 fclose(input);
38 fprintf(stderr, "Failed to allocate %ld bytes\n", size);
39 return 1;
40 }
41
42 size_t bytes_read = fread(data, 1, size, input);
43 fclose(input);
44
45 if (bytes_read != size) {
46 free(data);
47 fprintf(stderr, "Failed to read %s\n", argv[1]);
48 return 1;
49 }
50
51 int result = LLVMFuzzerTestOneInput(data, size);
52
53 free(data);
54
55 return result;
56 }
OLDNEW
« 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