udev: String substitutions can be done in ENV, too
[systemd_ALT.git] / src / udev / fuzz-udev-rules.c
blobaff176eb1bddcb701cd5f7806edf0a552f3d6249
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include <stdio.h>
5 #include "fd-util.h"
6 #include "fs-util.h"
7 #include "fuzz.h"
8 #include "tests.h"
9 #include "tmpfile-util.h"
10 #include "udev-rules.h"
12 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
13 _cleanup_(udev_rules_freep) UdevRules *rules = NULL;
14 _cleanup_fclose_ FILE *f = NULL;
15 _cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-udev-rules.XXXXXX";
16 int r;
18 if (outside_size_range(size, 0, 65536))
19 return 0;
21 if (!getenv("SYSTEMD_LOG_LEVEL"))
22 log_set_max_level(LOG_CRIT);
24 assert_se(fmkostemp_safe(filename, "r+", &f) == 0);
25 if (size != 0)
26 assert_se(fwrite(data, size, 1, f) == 1);
27 fflush(f);
29 assert_se(rules = udev_rules_new(RESOLVE_NAME_EARLY));
30 r = udev_rules_parse_file(rules, filename, /* extra_checks = */ false, NULL);
31 log_info_errno(r, "Parsing %s: %m", filename);
32 assert_se(r >= 0 || /* OK */
33 r == -ENOBUFS); /* line length exceeded */
35 return 0;