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 https://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
21 #ifdef TEST_SHARED_OBJECT
22 #define main main_exported
23 #endif
24
main(int argc,char ** argv)25 int main(int argc, char **argv) {
26
27 int fd = 0, cnt;
28 char buff[8];
29 char *buf = buff;
30
31 // we support command line parameter and stdin
32 if (argc == 2) {
33
34 buf = argv[1];
35
36 } else {
37
38 if (argc >= 3 && strcmp(argv[1], "-f") == 0) {
39
40 if ((fd = open(argv[2], O_RDONLY)) < 0) {
41
42 fprintf(stderr, "Error: unable to open %s\n", argv[2]);
43 exit(-1);
44
45 }
46
47 }
48
49 if ((cnt = read(fd, buf, sizeof(buf) - 1)) < 1) {
50
51 printf("Hum?\n");
52 return 1;
53
54 }
55
56 buf[cnt] = 0;
57
58 }
59
60 if (getenv("AFL_DEBUG")) fprintf(stderr, "test-instr: %s\n", buf);
61
62 // we support three input cases (plus a 4th if stdin is used but there is no
63 // input)
64 switch (buf[0]) {
65
66 case '0':
67 printf("Looks like a zero to me!\n");
68 break;
69
70 case '1':
71 printf("Pretty sure that is a one!\n");
72 break;
73
74 default:
75 printf("Neither one or zero? How quaint!\n");
76 break;
77
78 }
79
80 return 0;
81
82 }
83
84