1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 | // Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <fuzz.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <asiolink/io_service.h>
#include <cc/data.h>
#include <config/command_mgr.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcpsrv/cfgmgr.h>
#include <testutils/unix_control_client.h>
#include <util/filesystem.h>
#include <cassert><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace isc::asiolink;
using namespace isc::config;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::util;
using namespace isc::util::file;
using namespace std;
namespace {
static pid_t const PID(getpid());
static string const PID_STR(to_string(PID));
static string const KEA_DHCP6_CONF(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".conf");
static string const KEA_DHCP6_CSV(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".csv");
static string const SOCKET(KEA_FUZZ_DIR + "/kea-dhcp6-ctrl-" + PID_STR + ".sock");
static UnixControlClient CLIENT;
} // namespace
extern "C" {
int
LLVMFuzzerInitialize() {
static bool initialized(DoInitialization());
assert(initialized);
// "control-socket" is of explicit interest, but we also specify the memfile
// CSV location and the server-id to make sure that we don't get an error
// caused by an invalid file path.
writeToFile(KEA_DHCP6_CONF, R"(
{
"Dhcp6": {
"control-socket": {
"socket-name": ")" + SOCKET + R"(",
"socket-type": "unix"
},
"lease-database": {
"name": ")" + KEA_DHCP6_CSV + R"(",
"persist": false,
"type": "memfile"
},
"server-id": {
"type": "EN",
"enterprise-id": 2495,
"identifier": "0123456789",
"persist": false
}
}
}
)");
// Iterate through the interfaces and expect no errors.
for (IfacePtr const& interface : IfaceMgr::instance().getIfaces()) {
for (string const& error : interface->getErrors()) {
cout << error << endl;
}
assert(interface->getErrors().empty());
}
return 0;
}
int
LLVMFuzzerTearDown() {
try {
remove(KEA_DHCP6_CONF.c_str());
} catch (...) {
}
try {
remove(KEA_DHCP6_CSV.c_str());
} catch (...) {
}
try {
remove(SOCKET.c_str());
} catch (...) {
}
try {
remove((SOCKET + ".lock").c_str());
} catch (...) {
}
return 0;
}
int
LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
CfgMgr::instance().clear();
ControlledDhcpv6Srv server;
server.init(KEA_DHCP6_CONF);
assert(isSocket(SOCKET));
string const command(reinterpret_cast<char const*>(data), size);
CLIENT.connectToServer(SOCKET);
CLIENT.sendCommand(command);
ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
string response;
CLIENT.getResponse(response);
ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
CLIENT.disconnectFromServer();
ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
return 0;
}
} // extern "C"
|