Line | Count | Source |
1 | | // Copyright 2026 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | // |
15 | | //////////////////////////////////////////////////////////////////////////////// |
16 | | |
17 | | #define _GNU_SOURCE |
18 | | #include <sys/types.h> |
19 | | #include <sys/socket.h> |
20 | | #include <stdint.h> |
21 | | #include <stdio.h> |
22 | | #include <stdlib.h> |
23 | | #include <string.h> |
24 | | #include <netinet/in.h> |
25 | | #include <netinet/ip6.h> |
26 | | #include <net/if.h> |
27 | | #include "radvd.h" |
28 | | |
29 | | // Mock functions |
30 | | int sock = -1; |
31 | | int LL_DEBUG_LOG = 0; |
32 | | int log_method = L_STDERR; |
33 | | char *conf_file = NULL; |
34 | | char *pname = "fuzz_process"; |
35 | | |
36 | 6.39k | void dlog(int level, int flevel, char const *fmt, ...) {} |
37 | 19.9k | void flog(int level, char const *fmt, ...) {} |
38 | 0 | int get_debuglevel(void) { return 0; } |
39 | | |
40 | 0 | void set_debuglevel(int level) {} |
41 | | |
42 | 605 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
43 | 605 | if (size < sizeof(struct icmp6_hdr)) return 0; |
44 | | |
45 | 601 | struct Interface iface; |
46 | 601 | memset(&iface, 0, sizeof(iface)); |
47 | 601 | strcpy(iface.props.name, "lo"); |
48 | 601 | iface.props.if_index = 1; |
49 | 601 | iface.state_info.ready = 1; |
50 | 601 | iface.AdvSendAdvert = 1; |
51 | 601 | iface.UnicastOnly = 0; |
52 | | |
53 | | // We need to set if_addrs |
54 | 601 | struct in6_addr addr_ll; |
55 | 601 | memset(&addr_ll, 0, sizeof(addr_ll)); |
56 | 601 | addr_ll.s6_addr[0] = 0xfe; |
57 | 601 | addr_ll.s6_addr[1] = 0x80; |
58 | 601 | iface.props.if_addr = addr_ll; |
59 | | |
60 | 601 | struct sockaddr_in6 addr; |
61 | 601 | memset(&addr, 0, sizeof(addr)); |
62 | 601 | addr.sin6_family = AF_INET6; |
63 | | // Set link local address |
64 | 601 | addr.sin6_addr.s6_addr[0] = 0xfe; |
65 | 601 | addr.sin6_addr.s6_addr[1] = 0x80; |
66 | | |
67 | 601 | struct in6_pktinfo pkt_info; |
68 | 601 | memset(&pkt_info, 0, sizeof(pkt_info)); |
69 | 601 | pkt_info.ipi6_ifindex = 1; |
70 | | |
71 | 601 | int hoplimit = 255; |
72 | | |
73 | 601 | unsigned char *msg = (unsigned char *)malloc(size); |
74 | 601 | memcpy(msg, data, size); |
75 | | |
76 | 601 | process(sock, &iface, msg, size, &addr, &pkt_info, hoplimit); |
77 | | |
78 | 601 | free(msg); |
79 | 601 | return 0; |
80 | 605 | } |