]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-catalog.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / fuzz / fuzz-catalog.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "catalog.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_(unlink_tempfilep) char name[] = "/tmp/fuzz-catalog.XXXXXX";
11 _cleanup_close_ int fd = -1;
12 _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
13
14 if (!getenv("SYSTEMD_LOG_LEVEL"))
15 log_set_max_level(LOG_CRIT);
16
17 assert_se(h = hashmap_new(&catalog_hash_ops));
18
19 fd = mkostemp_safe(name);
20 assert_se(fd >= 0);
21 assert_se(write(fd, data, size) == (ssize_t) size);
22
23 (void) catalog_import_file(h, name);
24
25 return 0;
26 }