]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-udev-database.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / fuzz / fuzz-udev-database.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "device-private.h"
4 #include "fd-util.h"
5 #include "fs-util.h"
6 #include "fuzz.h"
7 #include "tmpfile-util.h"
8
9 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
10 _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
11 _cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-udev-database.XXXXXX";
12 _cleanup_fclose_ FILE *f = NULL;
13
14 if (!getenv("SYSTEMD_LOG_LEVEL"))
15 log_set_max_level(LOG_CRIT);
16
17 assert_se(fmkostemp_safe(filename, "r+", &f) == 0);
18 if (size != 0)
19 assert_se(fwrite(data, size, 1, f) == 1);
20
21 fflush(f);
22 assert_se(sd_device_new_from_syspath(&dev, "/sys/class/net/lo") >= 0);
23 (void) device_read_db_internal_filename(dev, filename);
24 return 0;
25 }