]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3953] Fix a static initialization race in fuzzers. Turn KEA_FUZZ_DIR into a function
authorAndrei Pavel <andrei@isc.org>
Tue, 17 Jun 2025 09:04:00 +0000 (12:04 +0300)
committerAndrei Pavel <andrei@isc.org>
Thu, 19 Jun 2025 14:16:55 +0000 (17:16 +0300)
fuzz/fuzz.cc
fuzz/fuzz.h
fuzz/fuzz_config_kea_dhcp4.cc
fuzz/fuzz_config_kea_dhcp6.cc
fuzz/fuzz_http_endpoint_kea_dhcp4.cc
fuzz/fuzz_http_endpoint_kea_dhcp6.cc
fuzz/fuzz_packets_kea_dhcp4.cc
fuzz/fuzz_packets_kea_dhcp6.cc
fuzz/fuzz_unix_socket_kea_dhcp4.cc
fuzz/fuzz_unix_socket_kea_dhcp6.cc

index f77354f44e4b2674920f254d0ef82480a0c3543c..85467e553c0f023481be03da5748a97fdc8e9569 100644 (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
 // 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);
index f92d73a155571c437f106c80b17fdf3314b50491..e94aa200ec784c19ab5dd422fe1797fdba196583 100644 (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
 // 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();
index 7cf779ff9ac2073f7cf3af61f50f9333f68b815e..47bc79557785ffd6c54c18e1761b692fb7ab4886 100644 (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
 // 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
 
index 9e11552c8f54ea20aeab15e5329ca53b5e58a83e..ee24bf0ef0655250be577bf1f15000cf6613910e 100644 (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
 // 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
 
index 68521b10f695f534d0aeb798b92636142ad91a1c..e76f91d21ac6d68b92257f69f93f8be0e6e5bb3e 100644 (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
 // 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;
index 48165d7c23f3336ddc416fd43ae4ca2041b4777c..95230f3a4a380b399fd6fd940ae611bf3bedf534 100644 (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
 // 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;
index 6427d65c9a24b1069cd200d3381dfbc4efc1b640..ade190c8a630b2729812ff7e698d3b11d658fde4 100644 (file)
@@ -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;
 
index 38d0b35c85acaee68755dc9d0b8fa0ac3a30531b..ed96c99cd042f7a88b5c9ef475f1cb6ce3864c68 100644 (file)
@@ -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;
 
index 1537f1012073f15b3a7762fa4990281bf7b340e7..1053cf0f830985cd67e8abb8f93721ab83db79e9 100644 (file)
 #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;
 
index e545fbd4d2cd595794b16b5b3b512292bce6db13..f14490a539f290458532e24d0287125a86f31b5e 100644 (file)
@@ -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;