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
This commit is contained in:
Evgeny Vereshchagin
2024-03-05 12:40:28 +09:00
committed by Yu Watanabe
parent e0270bab43
commit 1500b656cd
+5
View 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);