]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz: dump LLDP neighbors JSON too
authorEvgeny Vereshchagin <evvers@ya.ru>
Sun, 3 Mar 2024 21:04:39 +0000 (21:04 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Mar 2024 03:40:28 +0000 (12:40 +0900)
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

index 24146b709da5f828a2e42f35f747f2b592fadbac..dad1038ca0b206db28bf07711e891065e9e09902 100644 (file)
@@ -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);