From 1500b656cd6e4500dd0514d90c27fe0e16b14c77 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Sun, 3 Mar 2024 21:04:39 +0000 Subject: [PATCH] fuzz: dump LLDP neighbors JSON too to make sure all the fields are in more or less good shape. It's a follow-up to https://github.com/systemd/systemd/pull/31583 --- src/libsystemd-network/fuzz-lldp-rx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libsystemd-network/fuzz-lldp-rx.c b/src/libsystemd-network/fuzz-lldp-rx.c index 24146b709da..dad1038ca0b 100644 --- a/src/libsystemd-network/fuzz-lldp-rx.c +++ b/src/libsystemd-network/fuzz-lldp-rx.c @@ -10,6 +10,7 @@ #include "fuzz.h" #include "lldp-network.h" #include "lldp-rx-internal.h" +#include "memstream-util.h" static int test_fd[2] = EBADF_PAIR; @@ -24,6 +25,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_(sd_event_unrefp) sd_event *e = NULL; _cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(memstream_done) MemStream m = {}; + FILE *f; if (outside_size_range(size, 0, 2048)) return 0; @@ -40,6 +43,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { assert_se(sd_event_run(e, 0) >= 0); assert_se(lldp_rx_build_neighbors_json(lldp_rx, &v) >= 0); + assert_se(f = memstream_init(&m)); + (void) json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR, f, NULL); assert_se(sd_lldp_rx_stop(lldp_rx) >= 0); assert_se(sd_lldp_rx_detach_event(lldp_rx) >= 0); -- 2.47.3