1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include "fd-util.h"
4 #include "fs-util.h"
5 #include "fuzz.h"
6 #include "networkd-manager.h"
7 #include "tmpfile-util.h"
8 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)9 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
10         _cleanup_(manager_freep) Manager *manager = NULL;
11         _cleanup_fclose_ FILE *f = NULL;
12         _cleanup_(unlink_tempfilep) char netdev_config[] = "/tmp/fuzz-networkd.XXXXXX";
13 
14         if (outside_size_range(size, 0, 65536))
15                 return 0;
16 
17         if (!getenv("SYSTEMD_LOG_LEVEL"))
18                 log_set_max_level(LOG_CRIT);
19 
20         assert_se(fmkostemp_safe(netdev_config, "r+", &f) == 0);
21         if (size != 0)
22                 assert_se(fwrite(data, size, 1, f) == 1);
23 
24         fflush(f);
25         assert_se(manager_new(&manager, /* test_mode = */ true) >= 0);
26         (void) netdev_load_one(manager, netdev_config);
27         return 0;
28 }
29