1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)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_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
13 
14         if (!getenv("SYSTEMD_LOG_LEVEL"))
15                 log_set_max_level(LOG_CRIT);
16 
17         assert_se(h = ordered_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 }
27