1 /*
2 american fuzzy lop++ - a trivial program to test the build
3 --------------------------------------------------------
4 Originally written by Michal Zalewski
5 Copyright 2014 Google Inc. All rights reserved.
6 Copyright 2019-2024 AFLplusplus Project. All rights reserved.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at:
10 http://www.apache.org/licenses/LICENSE-2.0
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <string.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include <limits.h>
21
22 __AFL_FUZZ_INIT();
23
24 /* To ensure checks are not optimized out it is recommended to disable
25 code optimization for the fuzzer harness main() */
26 #pragma clang optimize off
27 #pragma GCC optimize("O0")
28
main(int argc,char ** argv)29 int main(int argc, char **argv) {
30
31 __AFL_INIT();
32 unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF;
33
34 while (__AFL_LOOP(UINT_MAX)) { // if you have 100% stability
35
36 unsigned int len = __AFL_FUZZ_TESTCASE_LEN;
37
38 #ifdef _AFL_DOCUMENT_MUTATIONS
39 static unsigned int counter = 0;
40 char fn[32];
41 sprintf(fn, "%09u:test-instr", counter);
42 int fd_doc = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600);
43 if (fd_doc >= 0) {
44
45 if (write(fd_doc, buf, len) != __afl_fuzz_len) {
46
47 fprintf(stderr, "write of mutation file failed: %s\n", fn);
48 unlink(fn);
49
50 }
51
52 close(fd_doc);
53
54 }
55
56 counter++;
57 #endif
58
59 // fprintf(stderr, "len: %u\n", len);
60
61 if (!len) continue;
62
63 if (buf[0] == '0')
64 printf("Looks like a zero to me!\n");
65 else if (buf[0] == '1')
66 printf("Pretty sure that is a one!\n");
67 else
68 printf("Neither one or zero? How quaint!\n");
69
70 }
71
72 return 0;
73
74 }
75
76