summaryrefslogtreecommitdiff
path: root/src/fuzz
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2019-03-11 12:43:00 +0100
committerFrantisek Sumsal <frantisek@sumsal.cz>2019-03-11 14:12:06 +0100
commit04ddab1462f53430b3977362428dea20b8ee3122 (patch)
tree7ee452955e5b3a40276805666370be14ae4adbee /src/fuzz
parent18d51b45097f510676ce0ae90ff8becdd3564f3c (diff)
downloadsystemd-04ddab1462f53430b3977362428dea20b8ee3122.tar.gz
fuzz: add hostname-util fuzzer
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-hostname-util.c28
-rw-r--r--src/fuzz/meson.build4
2 files changed, 32 insertions, 0 deletions
diff --git a/src/fuzz/fuzz-hostname-util.c b/src/fuzz/fuzz-hostname-util.c
new file mode 100644
index 0000000000..deaf8112ba
--- /dev/null
+++ b/src/fuzz/fuzz-hostname-util.c
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <errno.h>
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fuzz.h"
+#include "hostname-util.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ _cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *ret = NULL;
+
+ if (size == 0)
+ return 0;
+
+ f = fmemopen((char*) data, size, "re");
+ assert_se(f);
+
+ /* We don't want to fill the logs with messages about parse errors.
+ * Disable most logging if not running standalone */
+ if (!getenv("SYSTEMD_LOG_LEVEL"))
+ log_set_max_level(LOG_CRIT);
+
+ (void) read_etc_hostname_stream(f, &ret);
+
+ return 0;
+}
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
index d09006f640..e851d4e764 100644
--- a/src/fuzz/meson.build
+++ b/src/fuzz/meson.build
@@ -120,4 +120,8 @@ fuzzers += [
[['src/fuzz/fuzz-env-file.c'],
[libshared],
[]],
+
+ [['src/fuzz/fuzz-hostname-util.c'],
+ [libshared],
+ []],
]