xref: /aosp_15_r20/external/AFLplusplus/test/test-cmplog.c (revision 08b48e0b10e97b33e7b60c5b6e2243bd915777f2)
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdint.h>
4 #include <stdarg.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <unistd.h>
8 
LLVMFuzzerTestOneInput(const uint8_t * buf,size_t i)9 int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t i) {
10 
11   if (i < 15) return -1;
12   if (buf[0] != 'A') return 0;
13   if (buf[1] != 'B') return 0;
14   if (buf[2] != 'C') return 0;
15   if (buf[3] != 'D') return 0;
16   int *icmp = (int *)(buf + 4);
17   if (*icmp != 0x69694141) return 0;
18   if (memcmp(buf + 8, "1234EF", 6) == 0) abort();
19   return 0;
20 
21 }
22 
23 #ifdef __AFL_COMPILER
main(int argc,char * argv[])24 int main(int argc, char *argv[]) {
25 
26   unsigned char buf[1024];
27   ssize_t       i;
28   while (__AFL_LOOP(1000)) {
29 
30     i = read(0, (char *)buf, sizeof(buf) - 1);
31     if (i > 0) buf[i] = 0;
32     LLVMFuzzerTestOneInput(buf, i);
33 
34   }
35 
36   return 0;
37 
38 }
39 
40 #endif
41 
42