2
0
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:
Andrei Pavel 2025-06-17 12:04:00 +03:00
parent 9b8b7f24ef
commit f41fb2541f
No known key found for this signature in database
GPG Key ID: D4E804481939CB21
10 changed files with 32 additions and 30 deletions

View File

@ -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 // 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 // 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 isc::util::file;
using namespace std; 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; extern "C" {
// 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();
bool bool
DoInitialization() { DoInitialization() {
@ -34,12 +34,12 @@ DoInitialization() {
// Spoof the logger just enough to not get LoggingNotInitialized thrown. // Spoof the logger just enough to not get LoggingNotInitialized thrown.
// We explicitly don't want any logging during fuzzing for performance reasons. // 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); setenv("KEA_LFC_EXECUTABLE", "/bin/true", 0);
if (!getenv("DEBUG")) { if (!getenv("DEBUG")) {
setenv("KEA_LOGGER_DESTINATION", "/dev/null", 0); 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()) { if (!isc::log::isLoggingInitialized()) {
isc::log::initLogger("fuzzer"); isc::log::initLogger("fuzzer");
Daemon::loggerInit("fuzzer", /* verbose = */ false); Daemon::loggerInit("fuzzer", /* verbose = */ false);

View File

@ -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 // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
@ -9,10 +9,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
extern "C" { std::string KEA_FUZZ_DIR();
extern std::string KEA_FUZZ_DIR; extern "C" {
extern std::string KEA_LFC;
bool bool
DoInitialization(); DoInitialization();

View File

@ -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 // 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 // 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 pid_t const PID(getpid());
static string const PID_STR(to_string(PID)); 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 } // namespace

View File

@ -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 // 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 // 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 pid_t const PID(getpid());
static string const PID_STR(to_string(PID)); 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 } // namespace

View File

@ -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 // 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 // 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 pid_t const PID(getpid());
static string const PID_STR(to_string(PID)); static string const PID_STR(to_string(PID));
static string const ADDRESS("127.0.0.1"); 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_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_CSV(KEA_FUZZ_DIR() + "/kea-dhcp4-" + PID_STR + ".csv");
static int PORT; static int PORT;
static string PORT_STR; static string PORT_STR;

View File

@ -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 // 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 // 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 pid_t const PID(getpid());
static string const PID_STR(to_string(PID)); static string const PID_STR(to_string(PID));
static string const ADDRESS("::1"); static string const ADDRESS("::1");
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");
static string const KEA_DHCP6_CSV(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".csv"); static string const KEA_DHCP6_CSV(KEA_FUZZ_DIR() + "/kea-dhcp6-" + PID_STR + ".csv");
static int PORT; static int PORT;
static string PORT_STR; static string PORT_STR;

View File

@ -28,7 +28,7 @@ using namespace std;
namespace { 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_INTERFACE;
static string KEA_DHCP4_FUZZING_ADDRESS; static string KEA_DHCP4_FUZZING_ADDRESS;

View File

@ -28,7 +28,7 @@ using namespace std;
namespace { 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_INTERFACE;
static string KEA_DHCP6_FUZZING_ADDRESS; static string KEA_DHCP6_FUZZING_ADDRESS;

View File

@ -14,17 +14,20 @@
#include <config/unix_command_config.h> #include <config/unix_command_config.h>
#include <dhcp4/ctrl_dhcp4_srv.h> #include <dhcp4/ctrl_dhcp4_srv.h>
#include <dhcpsrv/cfgmgr.h> #include <dhcpsrv/cfgmgr.h>
#include <testutils/env_var_wrapper.h>
#include <testutils/unix_control_client.h> #include <testutils/unix_control_client.h>
#include <util/filesystem.h> #include <util/filesystem.h>
#include <cassert> #include <cassert>
#include <cstdlib>
using namespace isc::asiolink; using namespace isc::asiolink;
using namespace isc::config; using namespace isc::config;
using namespace isc::data; using namespace isc::data;
using namespace isc::dhcp; using namespace isc::dhcp;
using namespace isc::dhcp::test; using namespace isc::dhcp::test;
using namespace isc::test;
using namespace isc::util; using namespace isc::util;
using namespace isc::util::file; using namespace isc::util::file;
using namespace std; using namespace std;
@ -33,9 +36,9 @@ namespace {
static pid_t const PID(getpid()); static pid_t const PID(getpid());
static string const PID_STR(to_string(PID)); 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");
static string const KEA_DHCP4_CSV(KEA_FUZZ_DIR + "/kea-dhcp4-" + PID_STR + ".csv"); 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 SOCKET(KEA_FUZZ_DIR() + "/kea-dhcp4-ctrl-" + PID_STR + ".sock");
static UnixControlClient TEST_CLIENT; static UnixControlClient TEST_CLIENT;

View File

@ -33,9 +33,9 @@ namespace {
static pid_t const PID(getpid()); static pid_t const PID(getpid());
static string const PID_STR(to_string(PID)); 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");
static string const KEA_DHCP6_CSV(KEA_FUZZ_DIR + "/kea-dhcp6-" + PID_STR + ".csv"); 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 SOCKET(KEA_FUZZ_DIR() + "/kea-dhcp6-ctrl-" + PID_STR + ".sock");
static UnixControlClient TEST_CLIENT; static UnixControlClient TEST_CLIENT;