2025-01-28 10:06:26 +01:00
|
|
|
// Copyright (C) 2024-2025 Internet Systems Consortium, Inc. ("ISC")
|
2024-10-15 12:41:41 +03:00
|
|
|
//
|
|
|
|
// 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 <asiolink/io_service.h>
|
|
|
|
#include <cc/data.h>
|
|
|
|
#include <config/command_mgr.h>
|
2025-05-19 14:54:56 +03:00
|
|
|
#include <config/unix_command_config.h>
|
2024-10-15 12:41:41 +03:00
|
|
|
#include <dhcp6/ctrl_dhcp6_srv.h>
|
|
|
|
#include <dhcpsrv/cfgmgr.h>
|
|
|
|
#include <testutils/unix_control_client.h>
|
|
|
|
|
|
|
|
#include <util/filesystem.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
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));
|
2025-06-17 12:04:00 +03:00
|
|
|
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");
|
2024-10-15 12:41:41 +03:00
|
|
|
|
2024-12-05 01:37:22 +02:00
|
|
|
static UnixControlClient TEST_CLIENT;
|
2024-10-15 12:41:41 +03:00
|
|
|
|
|
|
|
} // 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"(",
|
2024-10-22 17:39:57 +03:00
|
|
|
"persist": false,
|
2024-10-15 12:41:41 +03:00
|
|
|
"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;
|
2025-05-19 14:54:56 +03:00
|
|
|
Path socket_path(SOCKET);
|
|
|
|
auto dir = socket_path.parentDirectory();
|
|
|
|
auto path = UnixCommandConfig::getSocketPath(true, dir);
|
|
|
|
UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
|
|
|
|
|
2024-10-15 12:41:41 +03:00
|
|
|
server.init(KEA_DHCP6_CONF);
|
|
|
|
assert(isSocket(SOCKET));
|
|
|
|
|
|
|
|
string const command(reinterpret_cast<char const*>(data), size);
|
2024-12-05 01:37:22 +02:00
|
|
|
TEST_CLIENT.connectToServer(SOCKET);
|
|
|
|
TEST_CLIENT.sendCommand(command);
|
2024-10-15 12:41:41 +03:00
|
|
|
ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
|
|
|
|
string response;
|
2024-12-05 01:37:22 +02:00
|
|
|
TEST_CLIENT.getResponse(response);
|
2024-10-15 12:41:41 +03:00
|
|
|
ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
|
2024-12-05 01:37:22 +02:00
|
|
|
TEST_CLIENT.disconnectFromServer();
|
2024-10-15 12:41:41 +03:00
|
|
|
ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|