summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/resolve/fuzz-etc-hosts.c20
-rw-r--r--src/resolve/meson.build7
-rwxr-xr-xtools/oss-fuzz.sh5
3 files changed, 32 insertions, 0 deletions
diff --git a/src/resolve/fuzz-etc-hosts.c b/src/resolve/fuzz-etc-hosts.c
new file mode 100644
index 0000000000..050c85dab4
--- /dev/null
+++ b/src/resolve/fuzz-etc-hosts.c
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "fd-util.h"
+#include "fuzz.h"
+#include "resolved-etc-hosts.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ _cleanup_fclose_ FILE *f = NULL;
+ _cleanup_(etc_hosts_free) EtcHosts h = {};
+
+ if (!getenv("SYSTEMD_LOG_LEVEL"))
+ log_set_max_level(LOG_CRIT);
+
+ f = data_to_file(data, size);
+ assert_se(f);
+
+ (void) etc_hosts_parse(&h, f);
+
+ return 0;
+}
diff --git a/src/resolve/meson.build b/src/resolve/meson.build
index 1fee993d0a..eeaea3411f 100644
--- a/src/resolve/meson.build
+++ b/src/resolve/meson.build
@@ -221,4 +221,11 @@ fuzzers += [
libshared],
[lib_openssl_or_gcrypt,
libm]],
+ [files('fuzz-etc-hosts.c',
+ 'resolved-etc-hosts.c',
+ 'resolved-etc-hosts.h'),
+ [libsystemd_resolve_core,
+ libshared],
+ [lib_openssl_or_gcrypt,
+ libm]],
]
diff --git a/tools/oss-fuzz.sh b/tools/oss-fuzz.sh
index cff90145ce..1d7412a81b 100755
--- a/tools/oss-fuzz.sh
+++ b/tools/oss-fuzz.sh
@@ -73,6 +73,11 @@ done
zip -jqr "$OUT/fuzz-bcd_seed_corpus.zip" "$bcd"
rm -rf "$bcd"
+hosts=$(mktemp)
+wget -O "$hosts" https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
+zip -jq "$OUT/fuzz-etc-hosts_seed_corpus.zip" "$hosts"
+rm -rf "$hosts"
+
# The seed corpus is a separate flat archive for each fuzzer,
# with a fixed name ${fuzzer}_seed_corpus.zip.
for d in "$(dirname "$0")/../test/fuzz/fuzz-"*; do