summaryrefslogtreecommitdiffstats
path: root/fuzz/fuzz_config_kea_dhcp6.cc
diff options
context:
space:
mode:
authorAndrei Pavel <andrei@isc.org>2024-10-15 11:41:41 +0200
committerAndrei Pavel <andrei@isc.org>2024-10-23 15:40:31 +0200
commita96168e7625541f15fc58811104c8da0303646f4 (patch)
treeae63bde11d86d1276c6efe4bb000a24c5e6486c7 /fuzz/fuzz_config_kea_dhcp6.cc
parent[#3605] Remove extra semis (diff)
downloadkea-a96168e7625541f15fc58811104c8da0303646f4.tar.xz
kea-a96168e7625541f15fc58811104c8da0303646f4.zip
[#3605] Integrate a new fuzzing solution in Kea
The solution is based on clusterfuzzlite, libfuzzer, and oss-fuzz technologies. - Add the .clusterfuzzlite directory. - Add the fuzz CI stage and fuzzing CI jobs. - Add the fuzzing targets in the fuzz directory. - Document fuzzing in doxygen.
Diffstat (limited to 'fuzz/fuzz_config_kea_dhcp6.cc')
-rw-r--r--fuzz/fuzz_config_kea_dhcp6.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/fuzz/fuzz_config_kea_dhcp6.cc b/fuzz/fuzz_config_kea_dhcp6.cc
new file mode 100644
index 0000000000..9e11552c8f
--- /dev/null
+++ b/fuzz/fuzz_config_kea_dhcp6.cc
@@ -0,0 +1,72 @@
+// 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 <cc/command_interpreter.h>
+#include <cc/user_context.h>
+#include <dhcp6/ctrl_dhcp6_srv.h>
+#include <dhcp6/json_config_parser.h>
+#include <dhcp6/parser_context.h>
+
+#include <cassert>
+#include <util/filesystem.h>
+#include <string>
+
+using namespace isc;
+using namespace isc::config;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::process;
+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");
+
+} // namespace
+
+extern "C" {
+
+int
+LLVMFuzzerInitialize() {
+ static bool initialized(DoInitialization());
+ assert(initialized);
+
+ return 0;
+}
+
+int
+LLVMFuzzerTearDown() {
+ try {
+ remove(KEA_DHCP6_CONF.c_str());
+ } catch (...) {
+ }
+ return 0;
+}
+
+int
+LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
+ // Create the config file.
+ string const string_config(reinterpret_cast<char const*>(data), size);
+ writeToFile(KEA_DHCP6_CONF, string_config);
+
+ // Configure the server.
+ ControlledDhcpv6Srv server;
+ try {
+ server.init(KEA_DHCP6_CONF);
+ } catch (BadValue const&) {
+ } catch (Dhcp6ParseError const&) {
+ }
+
+ return 0;
+}
+
+} // extern "C"