-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_test_script.c
65 lines (56 loc) · 1.51 KB
/
fuzz_test_script.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
61
62
63
64
65
#include "fuzz_test_script.h"
#include "fuzz_test_helper.h"
#include "logging.h"
#include "packet_to_string.h"
char **fuzz_scripts;
char *fuzz_script;
int fuzz_script_index;
void reinit_fuzzing_scripts() {
/**
* NOTE: the string for record fuzz packets and syscalls
*/
fuzz_script = malloc(3000);
fuzz_script_index = 0;
memset(fuzz_script, 0, 3000);
fuzz_scripts = malloc(1000 * sizeof(char *));
memset(fuzz_scripts, 0, 1000 * sizeof(char *));
}
void add_char_to_fuzz_script(char content) {
fuzz_script[fuzz_script_index] = content;
fuzz_script_index++;
}
void add_content_to_fuzz_script(char *content) {
for (int i = 0; i < strlen(content); i++) {
fuzz_script[fuzz_script_index] = content[i];
fuzz_script_index++;
}
}
void add_packet_to_fuzz_script(struct packet *p) {
char *dump = NULL;
char *error = NULL;
packet_to_string(p, DUMP_SHORT, &dump, &error);
if (error != NULL) {
add_content_to_fuzz_script("// ");
add_content_to_fuzz_script(error);
fuzz_script[fuzz_script_index] = '\n';
fuzz_script_index++;
}
add_content_to_fuzz_script("+0 < ");
add_content_to_fuzz_script(dump);
fuzz_script[fuzz_script_index] = '\n';
fuzz_script_index++;
DEBUG_FUZZP("dump is %s \n", dump);
DEBUG_FUZZP("error is %s \n", error);
free(dump);
free(error);
}
void update_fuzz_scripts() {
if (fuzz_script_index < 1) {
return;
}
fuzz_script[fuzz_script_index] = '\0';
DEBUG_FUZZP("fuzz_script is %s\n", fuzz_script);
fuzz_scripts[fuzz_loop_index] = strdup(fuzz_script);
fuzz_script_index = 0;
fuzz_loop_index++;
}