/src/kea/src/fuzz/fuzz_config_kea_dhcp6.cc
Line | Count | Source |
1 | | // Copyright (C) 2024-2026 Internet Systems Consortium, Inc. ("ISC") |
2 | | // |
3 | | // This Source Code Form is subject to the terms of the Mozilla Public |
4 | | // License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | | |
7 | | #include <config.h> |
8 | | |
9 | | #include <cc/command_interpreter.h> |
10 | | #include <cc/user_context.h> |
11 | | #include <dhcp6/ctrl_dhcp6_srv.h> |
12 | | #include <dhcp6/json_config_parser.h> |
13 | | #include <dhcp6/parser_context.h> |
14 | | #include <util/filesystem.h> |
15 | | |
16 | | #include <cassert> |
17 | | #include <iostream> |
18 | | #include <string> |
19 | | |
20 | | #include <fuzz.h> |
21 | | |
22 | | using namespace isc; |
23 | | using namespace isc::config; |
24 | | using namespace isc::data; |
25 | | using namespace isc::dhcp; |
26 | | using namespace isc::process; |
27 | | using namespace std; |
28 | | |
29 | | namespace { |
30 | | |
31 | | static pid_t const PID(getpid()); |
32 | | static string const PID_STR(to_string(PID)); |
33 | | static string const KEA_DHCP6_CONF(KEA_FUZZ_DIR() + "/kea-dhcp6-" + PID_STR + ".conf"); |
34 | | |
35 | | } // namespace |
36 | | |
37 | | extern "C" { |
38 | | |
39 | | int |
40 | 6 | LLVMFuzzerInitialize() { |
41 | 6 | static bool initialized(DoInitialization()); |
42 | 6 | assert(initialized); |
43 | | |
44 | 6 | return 0; |
45 | 6 | } |
46 | | |
47 | | int |
48 | 8 | LLVMFuzzerTearDown() { |
49 | 8 | try { |
50 | 8 | remove(KEA_DHCP6_CONF.c_str()); |
51 | 8 | } catch (...) { |
52 | 0 | } |
53 | 8 | return 0; |
54 | 8 | } |
55 | | |
56 | | int |
57 | 4.07k | LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { |
58 | | // Upper bound on oversized inputs: 512KiB. Last reported timeout was on 853KB. |
59 | 4.07k | if (size > 524288) { |
60 | 1 | std::cout << "Skipping: input size > 512KiB: " << size << std::endl; |
61 | 1 | return 0; |
62 | 1 | } |
63 | | |
64 | | // Create the config file. |
65 | 4.07k | string const string_config(reinterpret_cast<char const*>(data), size); |
66 | 4.07k | writeToFile(KEA_DHCP6_CONF, string_config); |
67 | | |
68 | | // Configure the server. |
69 | 4.07k | ControlledDhcpv6Srv server; |
70 | 4.07k | try { |
71 | 4.07k | server.init(KEA_DHCP6_CONF); |
72 | 4.07k | } catch (BadValue const&) { |
73 | 4.07k | } catch (Dhcp6ParseError const&) { |
74 | 0 | } catch (std::exception const&) { |
75 | 0 | } |
76 | | |
77 | 4.07k | return 0; |
78 | 4.07k | } |
79 | | |
80 | | } // extern "C" |