]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-lldp-rx: add missing assertions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Sep 2021 06:29:07 +0000 (15:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Sep 2021 08:55:19 +0000 (17:55 +0900)
src/libsystemd-network/lldp-neighbor.c
src/libsystemd-network/sd-lldp-rx.c

index 342e490603c91650af34566a940a9dd3f5758164..3ee8969e59208c420c7d40bf6a8d1f1090195535 100644 (file)
@@ -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);
 }
 
index 78a297b68fcb475206ba24667ba5c428c2db4474..fd3097b26b0460e1ce962e2d65aa2c0074bbe3ef 100644 (file)
@@ -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;