]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/fuzz-ndisc-rs.c
logs-show: use journal_add_matchf() and journal_add_match_pair()
[thirdparty/systemd.git] / src / libsystemd-network / fuzz-ndisc-rs.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <arpa/inet.h>
4 #include <netinet/icmp6.h>
5 #include <unistd.h>
6
7 #include "sd-ndisc.h"
8
9 #include "alloc-util.h"
10 #include "fd-util.h"
11 #include "fuzz.h"
12 #include "icmp6-util-unix.h"
13 #include "ndisc-internal.h"
14 #include "socket-util.h"
15
16 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
17 struct ether_addr mac_addr = {
18 .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
19 };
20 _cleanup_(sd_event_unrefp) sd_event *e = NULL;
21 _cleanup_(sd_ndisc_unrefp) sd_ndisc *nd = NULL;
22
23 if (outside_size_range(size, 0, 2048))
24 return 0;
25
26 fuzz_setup_logging();
27
28 assert_se(sd_event_new(&e) >= 0);
29 assert_se(sd_ndisc_new(&nd) >= 0);
30 assert_se(sd_ndisc_attach_event(nd, e, 0) >= 0);
31 assert_se(sd_ndisc_set_ifindex(nd, 42) >= 0);
32 assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0);
33 assert_se(sd_ndisc_start(nd) >= 0);
34 assert_se(write(test_fd[1], data, size) == (ssize_t) size);
35 (void) sd_event_run(e, UINT64_MAX);
36 assert_se(sd_ndisc_stop(nd) >= 0);
37 close(test_fd[1]);
38
39 return 0;
40 }