mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-22 09:57:41 +00:00
[#3953] Fix a static initialization race in fuzzers. Turn KEA_FUZZ_DIR into a function
This commit is contained in:
parent
9b8b7f24ef
commit
f41fb2541f
16
fuzz/fuzz.cc
16
fuzz/fuzz.cc
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2024-2025 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
|
||||
@ -21,12 +21,12 @@ using namespace isc::util::encode;
|
||||
using namespace isc::util::file;
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
string KEA_FUZZ_DIR() {
|
||||
static TemporaryDirectory TEMP_DIR = TemporaryDirectory();
|
||||
return TEMP_DIR.dirName();
|
||||
}
|
||||
|
||||
string KEA_LFC = isFile(KEA_LFC_INSTALLATION) ? KEA_LFC_INSTALLATION : KEA_LFC_SOURCES;
|
||||
// string KEA_FUZZ_DIR = isFile(KEA_FUZZ_DIR_INSTALLATION) ? KEA_FUZZ_DIR_INSTALLATION : KEA_FUZZ_DIR_SOURCES;
|
||||
TemporaryDirectory TEMP_DIR = TemporaryDirectory();
|
||||
string KEA_FUZZ_DIR = TEMP_DIR.dirName();
|
||||
extern "C" {
|
||||
|
||||
bool
|
||||
DoInitialization() {
|
||||
@ -34,12 +34,12 @@ DoInitialization() {
|
||||
|
||||
// Spoof the logger just enough to not get LoggingNotInitialized thrown.
|
||||
// We explicitly don't want any logging during fuzzing for performance reasons.
|
||||
setenv("KEA_LOCKFILE_DIR", KEA_FUZZ_DIR.c_str(), 0);
|
||||
setenv("KEA_LOCKFILE_DIR", KEA_FUZZ_DIR().c_str(), 0);
|
||||
setenv("KEA_LFC_EXECUTABLE", "/bin/true", 0);
|
||||
if (!getenv("DEBUG")) {
|
||||
setenv("KEA_LOGGER_DESTINATION", "/dev/null", 0);
|
||||
}
|
||||
setenv("KEA_PIDFILE_DIR", KEA_FUZZ_DIR.c_str(), 0);
|
||||
setenv("KEA_PIDFILE_DIR", KEA_FUZZ_DIR().c_str(), 0);
|
||||
if (!isc::log::isLoggingInitialized()) {
|
||||
isc::log::initLogger("fuzzer");
|
||||
Daemon::loggerInit("fuzzer", /* verbose = */ false);
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2024-2025 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
|
||||
@ -9,10 +9,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
std::string KEA_FUZZ_DIR();
|
||||
|
||||
extern std::string KEA_FUZZ_DIR;
|
||||
extern std::string KEA_LFC;
|
||||
extern "C" {
|
||||
|
||||
bool
|
||||
DoInitialization();
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2024-2025 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
|
||||
@ -29,7 +29,7 @@ namespace {
|
||||
|
||||
static pid_t const PID(getpid());
|
||||
static string const PID_STR(to_string(PID));
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".conf");
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR() + "/kea-dhcp4-" + PID_STR + ".conf");
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2024-2025 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
|
||||
@ -29,7 +29,7 @@ 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_CONF(KEA_FUZZ_DIR() + "/kea-dhcp6-" + PID_STR + ".conf");
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2024-2025 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
|
||||
@ -44,8 +44,8 @@ namespace {
|
||||
static pid_t const PID(getpid());
|
||||
static string const PID_STR(to_string(PID));
|
||||
static string const ADDRESS("127.0.0.1");
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".conf");
|
||||
static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".csv");
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR() + "/kea-dhcp4-" + PID_STR + ".conf");
|
||||
static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR() + "/kea-dhcp4-" + PID_STR + ".csv");
|
||||
|
||||
static int PORT;
|
||||
static string PORT_STR;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2024-2025 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
|
||||
@ -44,8 +44,8 @@ namespace {
|
||||
static pid_t const PID(getpid());
|
||||
static string const PID_STR(to_string(PID));
|
||||
static string const ADDRESS("::1");
|
||||
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 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 int PORT;
|
||||
static string PORT_STR;
|
||||
|
@ -28,7 +28,7 @@ using namespace std;
|
||||
|
||||
namespace {
|
||||
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR + "/kea-dhcp4.conf");
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR() + "/kea-dhcp4.conf");
|
||||
static string KEA_DHCP4_FUZZING_INTERFACE;
|
||||
static string KEA_DHCP4_FUZZING_ADDRESS;
|
||||
|
||||
|
@ -28,7 +28,7 @@ using namespace std;
|
||||
|
||||
namespace {
|
||||
|
||||
static string const KEA_DHCP6_CONF(KEA_FUZZ_DIR + "/kea-dhcp6.conf");
|
||||
static string const KEA_DHCP6_CONF(KEA_FUZZ_DIR() + "/kea-dhcp6.conf");
|
||||
static string KEA_DHCP6_FUZZING_INTERFACE;
|
||||
static string KEA_DHCP6_FUZZING_ADDRESS;
|
||||
|
||||
|
@ -14,17 +14,20 @@
|
||||
#include <config/unix_command_config.h>
|
||||
#include <dhcp4/ctrl_dhcp4_srv.h>
|
||||
#include <dhcpsrv/cfgmgr.h>
|
||||
#include <testutils/env_var_wrapper.h>
|
||||
#include <testutils/unix_control_client.h>
|
||||
|
||||
#include <util/filesystem.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace isc::asiolink;
|
||||
using namespace isc::config;
|
||||
using namespace isc::data;
|
||||
using namespace isc::dhcp;
|
||||
using namespace isc::dhcp::test;
|
||||
using namespace isc::test;
|
||||
using namespace isc::util;
|
||||
using namespace isc::util::file;
|
||||
using namespace std;
|
||||
@ -33,9 +36,9 @@ namespace {
|
||||
|
||||
static pid_t const PID(getpid());
|
||||
static string const PID_STR(to_string(PID));
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".conf");
|
||||
static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".csv");
|
||||
static string const SOCKET(KEA_FUZZ_DIR + "/kea-dhcp4-ctrl-" + PID_STR + ".sock");
|
||||
static string const KEA_DHCP4_CONF(KEA_FUZZ_DIR() + "/kea-dhcp4-" + PID_STR + ".conf");
|
||||
static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR() + "/kea-dhcp4-" + PID_STR + ".csv");
|
||||
static string const SOCKET(KEA_FUZZ_DIR() + "/kea-dhcp4-ctrl-" + PID_STR + ".sock");
|
||||
|
||||
static UnixControlClient TEST_CLIENT;
|
||||
|
||||
|
@ -33,9 +33,9 @@ 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 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 TEST_CLIENT;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user