]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: fuzz etc_hosts_parse
authorEvgeny Vereshchagin <evvers@ya.ru>
Thu, 20 Jan 2022 05:06:49 +0000 (05:06 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 Jan 2022 06:53:48 +0000 (15:53 +0900)
That's just a follow-up to https://github.com/systemd/systemd/pull/22179

src/resolve/fuzz-etc-hosts.c [new file with mode: 0644]
src/resolve/meson.build
tools/oss-fuzz.sh

diff --git a/src/resolve/fuzz-etc-hosts.c b/src/resolve/fuzz-etc-hosts.c
new file mode 100644 (file)
index 0000000..050c85d
--- /dev/null
@@ -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;
+}
index 1fee993d0a25551198cdeecdb82144ebb776552f..eeaea3411fe44fc802e5433cf45f99a8419be365 100644 (file)
@@ -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]],
 ]
index cff90145ce0a70be1a314c78f20e0890b8ca09e6..1d7412a81b7f578ea505eba0f6c0014dc214299e 100755 (executable)
@@ -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