]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
0f0a1dad | 2 | |
0f0a1dad | 3 | #include <arpa/inet.h> |
ef118d00 YW |
4 | #include <netinet/icmp6.h> |
5 | #include <unistd.h> | |
0f0a1dad | 6 | |
f26c38ed YW |
7 | #include "sd-ndisc.h" |
8 | ||
0f0a1dad | 9 | #include "alloc-util.h" |
19ee48a6 | 10 | #include "fd-util.h" |
0f0a1dad | 11 | #include "fuzz.h" |
f26c38ed | 12 | #include "icmp6-util.h" |
0f0a1dad | 13 | #include "ndisc-internal.h" |
f26c38ed | 14 | #include "socket-util.h" |
0f0a1dad | 15 | |
19ee48a6 | 16 | static int test_fd[2] = PIPE_EBADF; |
0f0a1dad EV |
17 | |
18 | int icmp6_bind_router_solicitation(int index) { | |
804a6a17 | 19 | assert_se(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) >= 0); |
0f0a1dad EV |
20 | return test_fd[0]; |
21 | } | |
22 | ||
23 | int icmp6_bind_router_advertisement(int index) { | |
24 | return -ENOSYS; | |
25 | } | |
26 | ||
27 | int icmp6_receive(int fd, void *iov_base, size_t iov_len, | |
28 | struct in6_addr *dst, triple_timestamp *timestamp) { | |
29 | assert_se(read(fd, iov_base, iov_len) == (ssize_t) iov_len); | |
30 | ||
31 | if (timestamp) | |
32 | triple_timestamp_get(timestamp); | |
33 | ||
34 | return 0; | |
35 | } | |
36 | ||
37 | int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) { | |
38 | return 0; | |
39 | } | |
40 | ||
41 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | |
42 | struct ether_addr mac_addr = { | |
43 | .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'} | |
44 | }; | |
45 | _cleanup_(sd_event_unrefp) sd_event *e = NULL; | |
46 | _cleanup_(sd_ndisc_unrefp) sd_ndisc *nd = NULL; | |
47 | ||
c4f883b7 | 48 | if (outside_size_range(size, 0, 2048)) |
9b7f73b0 ZJS |
49 | return 0; |
50 | ||
0f0a1dad EV |
51 | assert_se(sd_event_new(&e) >= 0); |
52 | assert_se(sd_ndisc_new(&nd) >= 0); | |
53 | assert_se(sd_ndisc_attach_event(nd, e, 0) >= 0); | |
54 | assert_se(sd_ndisc_set_ifindex(nd, 42) >= 0); | |
55 | assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0); | |
56 | assert_se(sd_ndisc_start(nd) >= 0); | |
57 | assert_se(write(test_fd[1], data, size) == (ssize_t) size); | |
f5fbe71d | 58 | (void) sd_event_run(e, UINT64_MAX); |
0f0a1dad EV |
59 | assert_se(sd_ndisc_stop(nd) >= 0); |
60 | close(test_fd[1]); | |
61 | ||
62 | return 0; | |
63 | } |