From 68de77e987c33ef3f9a8cfa9ce6d85d0798f9784 Mon Sep 17 00:00:00 2001 From: Matt Dunwoodie Date: Sun, 28 Mar 2021 09:19:47 +1100 Subject: Check iter != NULL The problem with checking peer != NULL is that we already dereference iter to get i_value. This is what was caught in the index == 0 bug reported on bugs@. Instead, we should assert that iter != NULL. This is likely to be removed when adjusting wg_noise.c in the not to distant future. --- sys/net/if_wg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/net/if_wg.c b/sys/net/if_wg.c index 3de52a588cb..807d08a7b6e 100644 --- a/sys/net/if_wg.c +++ b/sys/net/if_wg.c @@ -1965,9 +1965,9 @@ wg_index_drop(void *_sc, uint32_t key0) } mtx_leave(&sc->sc_index_mtx); - /* We expect a peer */ + /* We expect an index match */ + KASSERT(iter != NULL); peer = CONTAINER_OF(iter->i_value, struct wg_peer, p_remote); - KASSERT(peer != NULL); SLIST_INSERT_HEAD(&peer->p_unused_index, iter, i_unused_entry); } -- cgit v1.2.3-59-g8ed1b