-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstutter_libFuzzer_and_AFL.c
60 lines (58 loc) · 1.43 KB
/
stutter_libFuzzer_and_AFL.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
uint32_t *num = (uint32_t *)Data;
if (Size < sizeof(uint32_t) * 2)
return 0;
//num[0] = 0x00621a27u; num[1] = 0x00c01752u;
if (num[0] > 0x003e9ef4u && num[0] < 0x00649689u) {
if (num[1] > 0x00b10797u && num[1] < 0x00f2deebu) {
if ((num[0] * num[1]) == 0x00621a27u * 0x00c01752u) {
*((volatile uint8_t *)0) = 0;
}
}
}
return 0;
}
__attribute__((weak))
int main(int argc, char **argv) {
if (argc != 2) {
printf("%s <test case path>\n", argv[0]);
return -1;
}
FILE *fp = NULL;
fp = fopen(argv[1], "r");
if (fp == NULL) {
printf("fopen %s failed\n", argv[1]);
return -1;
}
if (fseek(fp, 0, SEEK_END) != 0) {
printf("fseek failed\n");
fclose(fp);
return -1;
}
long size = ftell(fp);
if (size < 0) {
printf("ftell failed\n");
fclose(fp);
return -1;
}
rewind(fp);
uint8_t *data = (uint8_t *)malloc(size);
if (data == NULL) {
printf("oom\n");
fclose(fp);
return -1;
}
if (fread(data, size, 1, fp) != 1) {
printf("fread failed\n");
free(data);
fclose(fp);
return -1;
}
fclose(fp);
LLVMFuzzerTestOneInput(data, size);
free(data);
return 0;
}