Coverage Report

Created: 2026-10-13 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz_process.c
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
5.10k
void dlog(int level, int flevel, char const *fmt, ...) {}
37
32.1k
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
627
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
43
627
    if (size < sizeof(struct icmp6_hdr)) return 0;
44
45
623
    struct Interface iface;
46
623
    memset(&iface, 0, sizeof(iface));
47
623
    strcpy(iface.props.name, "lo");
48
623
    iface.props.if_index = 1;
49
623
    iface.state_info.ready = 1;
50
623
    iface.AdvSendAdvert = 1;
51
623
    iface.UnicastOnly = 0;
52
    
53
    // We need to set if_addrs
54
623
    struct in6_addr addr_ll;
55
623
    memset(&addr_ll, 0, sizeof(addr_ll));
56
623
    addr_ll.s6_addr[0] = 0xfe;
57
623
    addr_ll.s6_addr[1] = 0x80;
58
623
    iface.props.if_addr = addr_ll;
59
    
60
623
    struct sockaddr_in6 addr;
61
623
    memset(&addr, 0, sizeof(addr));
62
623
    addr.sin6_family = AF_INET6;
63
    // Set link local address
64
623
    addr.sin6_addr.s6_addr[0] = 0xfe;
65
623
    addr.sin6_addr.s6_addr[1] = 0x80;
66
67
623
    struct in6_pktinfo pkt_info;
68
623
    memset(&pkt_info, 0, sizeof(pkt_info));
69
623
    pkt_info.ipi6_ifindex = 1;
70
71
623
    int hoplimit = 255;
72
73
623
    unsigned char *msg = (unsigned char *)malloc(size);
74
623
    memcpy(msg, data, size);
75
76
623
    process(sock, &iface, msg, size, &addr, &pkt_info, hoplimit);
77
78
623
    free(msg);
79
623
    return 0;
80
627
}