summaryrefslogtreecommitdiffstats
path: root/src/libsystemd-network/fuzz-dhcp-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-network/fuzz-dhcp-client.c')
-rw-r--r--src/libsystemd-network/fuzz-dhcp-client.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/libsystemd-network/fuzz-dhcp-client.c b/src/libsystemd-network/fuzz-dhcp-client.c
index 384972f..72787c4 100644
--- a/src/libsystemd-network/fuzz-dhcp-client.c
+++ b/src/libsystemd-network/fuzz-dhcp-client.c
@@ -7,8 +7,12 @@
#include "sd-dhcp-client.c"
#include "alloc-util.h"
+#include "dhcp-lease-internal.h"
#include "dhcp-network.h"
+#include "fs-util.h"
#include "fuzz.h"
+#include "network-internal.h"
+#include "tmpfile-util.h"
int dhcp_network_bind_raw_socket(
int ifindex,
@@ -52,6 +56,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint8_t bcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
_cleanup_(sd_dhcp_client_unrefp) sd_dhcp_client *client = NULL;
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
+ _cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
+ _cleanup_(unlink_tempfilep) char lease_file[] = "/tmp/fuzz-dhcp-client.XXXXXX";
+ _cleanup_close_ int fd = -1;
int res, r;
assert_se(setenv("SYSTEMD_NETWORK_TEST_MODE", "1", 1) >= 0);
@@ -75,8 +82,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
client->xid = 2;
client->state = DHCP_STATE_SELECTING;
- (void) client_handle_offer_or_rapid_ack(client, (DHCPMessage*) data, size, NULL);
+ if (client_handle_offer_or_rapid_ack(client, (DHCPMessage*) data, size, NULL) < 0)
+ goto end;
+ fd = mkostemp_safe(lease_file);
+ assert_se(fd >= 0);
+
+ r = dhcp_lease_save(client->lease, lease_file);
+ assert_se(r >= 0);
+
+ r = dhcp_lease_load(&lease, lease_file);
+ assert_se(r >= 0);
+
+end:
assert_se(sd_dhcp_client_stop(client) >= 0);
return 0;