aboutsummaryrefslogtreecommitdiff
path: root/docs/PersistentFuzzing.md
blob: f390716381b9d57fe394a9faef2f1189144fd3bb (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Persistent fuzzing #

Honggfuzz is capable of fuzzing APIs, which is to say; to test new data within the same process. This speeds-up the process of fuzzing APIs greatly

# Requirements for hardware-based counter-based fuzzing #
  * GNU/Linux

# HowTo #

Prepare a binary in the two following ways:

## ASAN-style (_LLVMFuzzerTestOneInput_) ##

Two functions must be provided

```c
int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len)
````

and optionally

```c
int LLVMFuzzerInitialize(int *argc, char ***argv)
```

### Example (test.c):
```c
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
	TestAPI(buf, len);
	return 0;
}
```

### Compilation
```shell
$ hfuzz_cc/hfuzz-clang test.c -o test
```

### Fuzzing
```shell
$ honggfuzz -P -- ./test
```

## HF_ITER style ##

A complete program needs to be prepared, using ```HF_ITER``` symbol to fetch new inputs from honggfuzz

### Example (test.c):

```c
#include <inttypes.h>

extern HF_ITER(uint8_t** buf, size_t* len);

int main(void) {
	for (;;) {
		size_t len;
		uint8_t *buf;

		HF_ITER(&buf, &len);

		ApiToBeFuzzed(buf, len);
	}
}
```

### Compilation

```shell
$ hfuzz_cc/hfuzz-clang test.c -o test
```

## Fuzzing

```
$ honggfuzz -P -- ./test
```