-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuzz-config.c
71 lines (55 loc) · 1.24 KB
/
fuzz-config.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
66
67
68
69
70
71
#include "config.h"
#include <string.h>
#include "libks/arena.h"
#include "libks/fuzzer.h"
#include "conf.h"
#include "log.h"
#include "mode.h"
struct fuzzer_context {
const char *mode;
struct arena *eternal;
struct arena *scratch;
};
static void *
init(int argc, char *argv[])
{
static struct fuzzer_context c;
log_disable();
c.mode = robsd_mode_str(ROBSD);
for (int i = 0; i < argc; i++) {
static const char key[] = "--mode=";
size_t keylen = sizeof(key) - 1;
if (strncmp(argv[i], key, keylen) == 0) {
const char *val = &argv[i][keylen];
enum robsd_mode mode;
if (robsd_mode_parse(val, &mode))
__builtin_trap();
c.mode = val;
}
}
c.eternal = arena_alloc();
c.scratch = arena_alloc();
return &c;
}
FUZZER_INIT(init);
static void
teardown(void *userdata)
{
struct fuzzer_context *c = userdata;
arena_free(c->scratch);
arena_free(c->eternal);
}
FUZZER_TEARDOWN(teardown);
static void
target(const char *path, void *userdata)
{
struct fuzzer_context *c = userdata;
struct config *config;
arena_scope(c->eternal, eternal_scope);
config = config_alloc(c->mode, path, &eternal_scope, c->scratch);
if (config == NULL)
__builtin_trap();
config_parse(config);
config_free(config);
}
FUZZER_TARGET_FILE(target);