| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "fd-util.h" |
| 4 |
#include "fuzz.h" |
| 5 |
#include "link-config.h" |
| 6 |
#include "tmpfile-util.h" |
| 7 |
|
| 8 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 9 |
_cleanup_(link_config_ctx_freep) LinkConfigContext *ctx = NULL; |
| 10 |
_cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-link-config.XXXXXX"; |
| 11 |
_cleanup_fclose_ FILE *f = NULL; |
| 12 |
|
| 13 |
if (outside_size_range(size, 0, 65536)) |
| 14 |
return 0; |
| 15 |
|
| 16 |
fuzz_setup_logging(); |
| 17 |
|
| 18 |
assert_se(fmkostemp_safe(filename, "r+", &f) == 0); |
| 19 |
if (size != 0) |
| 20 |
assert_se(fwrite(data, size, 1, f) == 1); |
| 21 |
|
| 22 |
fflush(f); |
| 23 |
assert_se(link_config_ctx_new(&ctx) >= 0); |
| 24 |
(void) link_load_one(ctx, filename); |
| 25 |
return 0; |
| 26 |
} |