]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/fuzz-lldp-rx.c
fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
[thirdparty/systemd.git] / src / libsystemd-network / fuzz-lldp-rx.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
28ffcec2
EV
2
3#include <errno.h>
4#include <unistd.h>
5
6#include "sd-event.h"
3a2ee855 7#include "sd-lldp-rx.h"
28ffcec2
EV
8
9#include "fd-util.h"
10#include "fuzz.h"
11#include "lldp-network.h"
12
71136404 13static int test_fd[2] = EBADF_PAIR;
28ffcec2
EV
14
15int lldp_network_bind_raw_socket(int ifindex) {
804a6a17 16 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
28ffcec2
EV
17 return -errno;
18
19 return test_fd[0];
20}
21
22int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
23 _cleanup_(sd_event_unrefp) sd_event *e = NULL;
35778343 24 _cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL;
28ffcec2 25
c4f883b7 26 if (outside_size_range(size, 0, 2048))
d92e7b8f
ZJS
27 return 0;
28
4820c9d4
FS
29 fuzz_setup_logging();
30
28ffcec2 31 assert_se(sd_event_new(&e) == 0);
35778343
YW
32 assert_se(sd_lldp_rx_new(&lldp_rx) >= 0);
33 assert_se(sd_lldp_rx_set_ifindex(lldp_rx, 42) >= 0);
34 assert_se(sd_lldp_rx_attach_event(lldp_rx, e, 0) >= 0);
35 assert_se(sd_lldp_rx_start(lldp_rx) >= 0);
28ffcec2
EV
36
37 assert_se(write(test_fd[1], data, size) == (ssize_t) size);
38 assert_se(sd_event_run(e, 0) >= 0);
39
35778343
YW
40 assert_se(sd_lldp_rx_stop(lldp_rx) >= 0);
41 assert_se(sd_lldp_rx_detach_event(lldp_rx) >= 0);
28ffcec2
EV
42 test_fd[1] = safe_close(test_fd[1]);
43
44 return 0;
45}