From: Yu Watanabe Date: Tue, 28 Sep 2021 06:29:07 +0000 (+0900) Subject: sd-lldp-rx: add missing assertions X-Git-Tag: v250-rc1~612^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90496cc68c21be8f891da3f742b6da32a0fafc22;p=thirdparty%2Fsystemd.git sd-lldp-rx: add missing assertions --- diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 342e490603c..3ee8969e592 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -11,6 +11,9 @@ #include "unaligned.h" static void lldp_neighbor_id_hash_func(const LLDPNeighborID *id, struct siphash *state) { + assert(id); + assert(state); + siphash24_compress(id->chassis_id, id->chassis_id_size, state); siphash24_compress(&id->chassis_id_size, sizeof(id->chassis_id_size), state); siphash24_compress(id->port_id, id->port_id_size, state); @@ -18,6 +21,9 @@ static void lldp_neighbor_id_hash_func(const LLDPNeighborID *id, struct siphash } int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y) { + assert(x); + assert(y); + return memcmp_nn(x->chassis_id, x->chassis_id_size, y->chassis_id, y->chassis_id_size) ?: memcmp_nn(x->port_id, x->port_id_size, y->port_id, y->port_id_size); } @@ -28,6 +34,9 @@ DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(lldp_neighbor_hash_ops, LLDPNeighborID, ll int lldp_neighbor_prioq_compare_func(const void *a, const void *b) { const sd_lldp_neighbor *x = a, *y = b; + assert(x); + assert(y); + return CMP(x->until, y->until); } diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 78a297b68fc..fd3097b26b0 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -403,10 +403,6 @@ _public_ int sd_lldp_rx_new(sd_lldp_rx **ret) { return 0; } -static int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) { - return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); -} - static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) { sd_lldp_rx *lldp_rx = userdata; int r; @@ -448,6 +444,15 @@ static int lldp_rx_start_timer(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *neighbor) lldp_rx->event_priority, "lldp-rx-timer", true); } +static inline int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) { + assert(a); + assert(b); + assert(*a); + assert(*b); + + return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); +} + _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { sd_lldp_neighbor **l = NULL, *n; int k = 0, r;