Skip to content

Commit f3917df

Browse files
author
Razvan Becheriu
committed
[#3605] fixed fuzz on BSD-like systems
1 parent f2f5b0e commit f3917df

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

fuzz/fuzz_packets_kea_dhcp4.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ LLVMFuzzerInitialize() {
4343

4444
setenv("KEA_DHCP4_FUZZING_ROTATE_PORT", "true", 0);
4545

46+
if (if_nametoindex("lo") > 0) {
47+
KEA_DHCP4_FUZZING_INTERFACE = string("lo");
48+
} else if (if_nametoindex("lo0") > 0) {
49+
KEA_DHCP4_FUZZING_INTERFACE = string("lo0");
50+
}
51+
4652
char const* interface(getenv("KEA_DHCP4_FUZZING_INTERFACE"));
47-
KEA_DHCP4_FUZZING_INTERFACE = string(interface ? interface : "lo");
53+
if (interface) {
54+
KEA_DHCP4_FUZZING_INTERFACE = string(interface);
55+
}
4856

4957
char const* address(getenv("KEA_DHCP4_FUZZING_ADDRESS"));
5058
KEA_DHCP4_FUZZING_ADDRESS = string(address ? address : "127.0.0.1");

fuzz/fuzz_packets_kea_dhcp6.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ LLVMFuzzerInitialize() {
4343

4444
setenv("KEA_DHCP6_FUZZING_ROTATE_PORT", "true", 0);
4545

46+
if (if_nametoindex("lo") > 0) {
47+
KEA_DHCP6_FUZZING_INTERFACE = string("lo");
48+
} else if (if_nametoindex("lo0") > 0) {
49+
KEA_DHCP6_FUZZING_INTERFACE = string("lo0");
50+
}
51+
4652
char const* interface(getenv("KEA_DHCP6_FUZZING_INTERFACE"));
47-
KEA_DHCP6_FUZZING_INTERFACE = string(interface ? interface : "lo");
53+
if (interface) {
54+
KEA_DHCP6_FUZZING_INTERFACE = string(interface);
55+
}
4856

4957
char const* address(getenv("KEA_DHCP6_FUZZING_ADDRESS"));
5058
KEA_DHCP6_FUZZING_ADDRESS = string(address ? address : "::1");

fuzz/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ main(int, char* argv[]) {
8181

8282
for (string& f : files) {
8383
// Read content from file.
84-
basic_ifstream<uint8_t> file(f, ios::binary);
84+
ifstream file(f, ios::binary);
8585

8686
if (!file.is_open()) {
8787
cerr << "ERROR: could not open file " << f << endl;
@@ -95,7 +95,7 @@ main(int, char* argv[]) {
9595

9696
// Read the entire file into a vector.
9797
vector<uint8_t> buffer(bytes);
98-
file.read(buffer.data(), bytes);
98+
file.read(reinterpret_cast<char*>(buffer.data()), bytes);
9999

100100
file.close();
101101

src/lib/dhcpsrv/tests/packet_fuzzer_unittest.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ TEST(PacketFuzzerTest, constructor) {
2121
// v6 requires valid interface. Skip positive test case.
2222

2323
// Negative test cases
24-
EXPECT_THROW_MSG(PacketFuzzer(547, "invalid_eth%", "fe80::1"), FuzzInitFail,
25-
"error retrieving interface ID for invalid_eth%: No such device");
24+
EXPECT_THROW(PacketFuzzer(547, "invalid_eth%", "fe80::1"), FuzzInitFail);
2625
EXPECT_THROW_MSG(PacketFuzzer(1234, "testeth", "abcd"), isc::asiolink::IOError,
2726
"Failed to convert string to address 'abcd': Invalid argument");
2827
}

0 commit comments

Comments
 (0)