/src/kea-fuzzer/fuzz_dhcpsrv_csv_lease.cc
Line | Count | Source |
1 | | // Copyright (C) 2025 Ada Logcis Ltd. |
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 <asiolink/io_address.h> |
10 | | #include <dhcp/duid.h> |
11 | | #include <dhcpsrv/csv_lease_file4.h> |
12 | | #include <dhcpsrv/csv_lease_file6.h> |
13 | | #include <dhcpsrv/lease.h> |
14 | | #include <dhcpsrv/testutils/lease_file_io.h> |
15 | | |
16 | | using namespace isc; |
17 | | using namespace isc::data; |
18 | | using namespace isc::dhcp; |
19 | | |
20 | 557 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { |
21 | 557 | char filename[256]; |
22 | 557 | sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |
23 | | |
24 | 557 | FILE *fp = fopen(filename, "wb"); |
25 | 557 | if (!fp) |
26 | 0 | return 0; |
27 | 557 | fwrite(Data, Size, 1, fp); |
28 | 557 | fclose(fp); |
29 | | |
30 | 557 | try { |
31 | 557 | CSVLeaseFile4 lease_file(filename); |
32 | 557 | lease_file.open(false); |
33 | 557 | Lease4Ptr lease; |
34 | 557 | lease_file.next(lease); |
35 | 557 | lease_file.close(); |
36 | 557 | } catch (const std::exception&) { |
37 | | // ignore any errors |
38 | 557 | } |
39 | | |
40 | 557 | try { |
41 | 557 | CSVLeaseFile6 lease_file(filename); |
42 | 557 | lease_file.open(false); |
43 | 557 | Lease6Ptr lease; |
44 | 557 | lease_file.next(lease); |
45 | 557 | lease_file.close(); |
46 | 557 | } catch (const std::exception&) { |
47 | | // ignore any errors |
48 | 557 | } |
49 | | |
50 | 557 | unlink(filename); |
51 | 557 | return 0; |
52 | 557 | } |