/src/git/oss-fuzz/fuzz-config.c
Line | Count | Source |
1 | | #include "git-compat-util.h" |
2 | | #include "config.h" |
3 | | |
4 | | int LLVMFuzzerTestOneInput(const uint8_t *, size_t); |
5 | | static int config_parser_callback(const char *, const char *, |
6 | | const struct config_context *, void *); |
7 | | |
8 | | static int config_parser_callback(const char *key, const char *value, |
9 | | const struct config_context *ctx UNUSED, |
10 | | void *data UNUSED) |
11 | 3.07k | { |
12 | | /* |
13 | | * Visit every byte of memory we are given to make sure the parser |
14 | | * gave it to us appropriately. We need to unconditionally return 0, |
15 | | * but we also want to prevent the strlen from being optimized away. |
16 | | */ |
17 | 3.07k | size_t c = strlen(key); |
18 | | |
19 | 3.07k | if (value) |
20 | 1.63k | c += strlen(value); |
21 | 3.07k | return c == SIZE_MAX; |
22 | 3.07k | } |
23 | | |
24 | | int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) |
25 | 2.62k | { |
26 | 2.62k | struct config_options config_opts = { 0 }; |
27 | | |
28 | 2.62k | config_opts.error_action = CONFIG_ERROR_SILENT; |
29 | 2.62k | git_config_from_mem(config_parser_callback, CONFIG_ORIGIN_BLOB, |
30 | 2.62k | "fuzztest-config", (const char *)data, size, NULL, |
31 | 2.62k | CONFIG_SCOPE_UNKNOWN, &config_opts); |
32 | 2.62k | return 0; |
33 | 2.62k | } |