summaryrefslogtreecommitdiff
path: root/src/fuzz
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2018-11-22 17:09:20 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-22 21:02:34 +0100
commit4928e8adba97f88a88ac79e4c3a1cc6c8fd8aff0 (patch)
tree8abcd70d03cb36ed961f77542473542230d00864 /src/fuzz
parentc43acf69e4eadd03f4a7c00eb1a88d8c52b43490 (diff)
downloadsystemd-4928e8adba97f88a88ac79e4c3a1cc6c8fd8aff0.tar.gz
systemd-4928e8adba97f88a88ac79e4c3a1cc6c8fd8aff0.tar.bz2
systemd-4928e8adba97f88a88ac79e4c3a1cc6c8fd8aff0.zip
tests: add a fuzzer for catalog_import_file
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-catalog.c26
-rw-r--r--src/fuzz/meson.build5
2 files changed, 31 insertions, 0 deletions
diff --git a/src/fuzz/fuzz-catalog.c b/src/fuzz/fuzz-catalog.c
new file mode 100644
index 0000000000..e40fe60bfb
--- /dev/null
+++ b/src/fuzz/fuzz-catalog.c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "catalog.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "fs-util.h"
+#include "fuzz.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-catalog.XXXXXX";
+ _cleanup_close_ int fd = -1;
+ _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+
+ if (!getenv("SYSTEMD_LOG_LEVEL"))
+ log_set_max_level(LOG_CRIT);
+
+ assert_se(h = hashmap_new(&catalog_hash_ops));
+
+ fd = mkostemp_safe(name);
+ assert_se(fd >= 0);
+ assert_se(write(fd, data, size) == (ssize_t) size);
+
+ (void) catalog_import_file(h, name);
+
+ return 0;
+}
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
index 1ae1c94f43..7196a0476c 100644
--- a/src/fuzz/meson.build
+++ b/src/fuzz/meson.build
@@ -5,6 +5,11 @@ fuzzers += [
[libshared],
[]],
+ [['src/fuzz/fuzz-catalog.c'],
+ [libjournal_core,
+ libshared],
+ []],
+
[['src/fuzz/fuzz-dns-packet.c',
dns_type_headers],
[libsystemd_resolve_core,