Skip to content

Commit 28ffcec

Browse files
committed
tests: add an lldp fuzzer
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 :-)
1 parent e0f768c commit 28ffcec

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

src/fuzz/fuzz-lldp.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
3+
#include <errno.h>
4+
#include <unistd.h>
5+
6+
#include "sd-event.h"
7+
#include "sd-lldp.h"
8+
9+
#include "fd-util.h"
10+
#include "fuzz.h"
11+
#include "lldp-network.h"
12+
13+
static int test_fd[2] = { -1, -1 };
14+
15+
int lldp_network_bind_raw_socket(int ifindex) {
16+
if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, test_fd) < 0)
17+
return -errno;
18+
19+
return test_fd[0];
20+
}
21+
22+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
23+
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
24+
_cleanup_(sd_lldp_unrefp) sd_lldp *lldp = NULL;
25+
26+
assert_se(sd_event_new(&e) == 0);
27+
assert_se(sd_lldp_new(&lldp) >= 0);
28+
assert_se(sd_lldp_set_ifindex(lldp, 42) >= 0);
29+
assert_se(sd_lldp_attach_event(lldp, e, 0) >= 0);
30+
assert_se(sd_lldp_start(lldp) >= 0);
31+
32+
assert_se(write(test_fd[1], data, size) == (ssize_t) size);
33+
assert_se(sd_event_run(e, 0) >= 0);
34+
35+
assert_se(sd_lldp_stop(lldp) >= 0);
36+
assert_se(sd_lldp_detach_event(lldp) >= 0);
37+
test_fd[1] = safe_close(test_fd[1]);
38+
39+
return 0;
40+
}

src/fuzz/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ fuzzers += [
2727
libshared],
2828
[]],
2929

30+
[['src/fuzz/fuzz-lldp.c'],
31+
[libshared,
32+
libsystemd_network],
33+
[]],
34+
3035
[['src/fuzz/fuzz-ndisc-rs.c',
3136
'src/libsystemd-network/dhcp-identifier.h',
3237
'src/libsystemd-network/dhcp-identifier.c',

test/fuzz/fuzz-lldp/basic

52 Bytes
Binary file not shown.

test/fuzz/fuzz-lldp/incomplete

31 Bytes
Binary file not shown.

test/fuzz/fuzz-lldp/oui

86 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)