Coverage Report

Created: 2026-02-14 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kea/fuzz/fuzz_config_kea_dhcp6.cc
Line
Count
Source
1
// Copyright (C) 2024-2025 Internet Systems Consortium, Inc. ("ISC")
2
//
3
// This Source Code Form is subject to the terms of the Mozilla Public
4
// License, v. 2.0. If a copy of the MPL was not distributed with this
5
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7
#include <config.h>
8
9
#include <fuzz.h>
10
11
#include <cc/command_interpreter.h>
12
#include <cc/user_context.h>
13
#include <dhcp6/ctrl_dhcp6_srv.h>
14
#include <dhcp6/json_config_parser.h>
15
#include <dhcp6/parser_context.h>
16
17
#include <cassert>
18
#include <util/filesystem.h>
19
#include <string>
20
21
using namespace isc;
22
using namespace isc::config;
23
using namespace isc::data;
24
using namespace isc::dhcp;
25
using namespace isc::process;
26
using namespace std;
27
28
namespace {
29
30
static pid_t const PID(getpid());
31
static string const PID_STR(to_string(PID));
32
static string const KEA_DHCP6_CONF(KEA_FUZZ_DIR() + "/kea-dhcp6-" + PID_STR + ".conf");
33
34
}  // namespace
35
36
extern "C" {
37
38
int
39
6
LLVMFuzzerInitialize() {
40
6
    static bool initialized(DoInitialization());
41
6
    assert(initialized);
42
43
6
    return 0;
44
6
}
45
46
int
47
8
LLVMFuzzerTearDown() {
48
8
    try {
49
8
        remove(KEA_DHCP6_CONF.c_str());
50
8
    } catch (...) {
51
0
    }
52
8
    return 0;
53
8
}
54
55
int
56
3.72k
LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
57
    // Create the config file.
58
3.72k
    string const string_config(reinterpret_cast<char const*>(data), size);
59
3.72k
    writeToFile(KEA_DHCP6_CONF, string_config);
60
61
    // Configure the server.
62
3.72k
    ControlledDhcpv6Srv server;
63
3.72k
    try {
64
3.72k
        server.init(KEA_DHCP6_CONF);
65
3.72k
    } catch (BadValue const&) {
66
3.72k
    } catch (Dhcp6ParseError const&) {
67
0
    }
68
69
3.72k
    return 0;
70
3.72k
}
71
72
}  // extern "C"