]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add an lldp fuzzer 10564/head
authorEvgeny Vereshchagin <evvers@ya.ru>
Mon, 29 Oct 2018 15:24:16 +0000 (15:24 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Mon, 29 Oct 2018 15:24:16 +0000 (15:24 +0000)
I went through my antique collection of fuzzers the other day
to see which ones I hadn't sent upstream yet. This one
seems to be nice to have and ready to be merged. As far as I can
tell, it hasn't managed to find anything useful yet,
but it's better to be safe than sorry especially when it comes to networking
code :-)

src/fuzz/fuzz-lldp.c [new file with mode: 0644]
src/fuzz/meson.build
test/fuzz/fuzz-lldp/basic [new file with mode: 0644]
test/fuzz/fuzz-lldp/incomplete [new file with mode: 0644]
test/fuzz/fuzz-lldp/oui [new file with mode: 0644]

diff --git a/src/fuzz/fuzz-lldp.c b/src/fuzz/fuzz-lldp.c
new file mode 100644 (file)
index 0000000..e88632c
--- /dev/null
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "sd-event.h"
+#include "sd-lldp.h"
+
+#include "fd-util.h"
+#include "fuzz.h"
+#include "lldp-network.h"
+
+static int test_fd[2] = { -1, -1 };
+
+int lldp_network_bind_raw_socket(int ifindex) {
+        if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, test_fd) < 0)
+                return -errno;
+
+        return test_fd[0];
+}
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+        _cleanup_(sd_event_unrefp) sd_event *e = NULL;
+        _cleanup_(sd_lldp_unrefp) sd_lldp *lldp = NULL;
+
+        assert_se(sd_event_new(&e) == 0);
+        assert_se(sd_lldp_new(&lldp) >= 0);
+        assert_se(sd_lldp_set_ifindex(lldp, 42) >= 0);
+        assert_se(sd_lldp_attach_event(lldp, e, 0) >= 0);
+        assert_se(sd_lldp_start(lldp) >= 0);
+
+        assert_se(write(test_fd[1], data, size) == (ssize_t) size);
+        assert_se(sd_event_run(e, 0) >= 0);
+
+        assert_se(sd_lldp_stop(lldp) >= 0);
+        assert_se(sd_lldp_detach_event(lldp) >= 0);
+        test_fd[1] = safe_close(test_fd[1]);
+
+        return 0;
+}
index 4c238493529617d9a876fe2fd12cadb9e6028859..ab92fe254804d4903f8a926e8cca6cb96d9246bf 100644 (file)
@@ -27,6 +27,11 @@ fuzzers += [
           libshared],
          []],
 
+        [['src/fuzz/fuzz-lldp.c'],
+         [libshared,
+          libsystemd_network],
+         []],
+
         [['src/fuzz/fuzz-ndisc-rs.c',
           'src/libsystemd-network/dhcp-identifier.h',
           'src/libsystemd-network/dhcp-identifier.c',
diff --git a/test/fuzz/fuzz-lldp/basic b/test/fuzz/fuzz-lldp/basic
new file mode 100644 (file)
index 0000000..43debea
Binary files /dev/null and b/test/fuzz/fuzz-lldp/basic differ
diff --git a/test/fuzz/fuzz-lldp/incomplete b/test/fuzz/fuzz-lldp/incomplete
new file mode 100644 (file)
index 0000000..53dce60
Binary files /dev/null and b/test/fuzz/fuzz-lldp/incomplete differ
diff --git a/test/fuzz/fuzz-lldp/oui b/test/fuzz/fuzz-lldp/oui
new file mode 100644 (file)
index 0000000..9c76c40
Binary files /dev/null and b/test/fuzz/fuzz-lldp/oui differ