1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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";
18 if (outside_size_range(size
, 0, 65536))
21 if (!getenv("SYSTEMD_LOG_LEVEL"))
22 log_set_max_level(LOG_CRIT
);
24 assert_se(fmkostemp_safe(filename
, "r+", &f
) == 0);
26 assert_se(fwrite(data
, size
, 1, f
) == 1);
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 */