wireguard: fix passing null pointer
Type: fix
Fixed coverity-issue CID 248517.
Originally possibly passing null pointer to one function and
directly dereferences it.
This patch fixes the problem by add a new condition.
Signed-off-by: Gabriel Oginski <gabrielx.oginski@intel.com>
Change-Id: I02fc6fb5d1cfd6138ea4ba2b1946fd8a7ef34d3b
diff --git a/src/plugins/wireguard/wireguard_input.c b/src/plugins/wireguard/wireguard_input.c
index dbdcaa0..ba5a1d6 100644
--- a/src/plugins/wireguard/wireguard_input.c
+++ b/src/plugins/wireguard/wireguard_input.c
@@ -902,6 +902,7 @@
last_rec_idx = data->receiver_index;
}
+ ASSERT (peer != NULL); /* this pointer never should be NULL */
if (PREDICT_FALSE (wg_input_post_process (vm, b[0], next, peer, data,
&is_keepalive) < 0))
goto trace;
diff --git a/src/plugins/wireguard/wireguard_noise.h b/src/plugins/wireguard/wireguard_noise.h
index e95211b..b436120 100644
--- a/src/plugins/wireguard/wireguard_noise.h
+++ b/src/plugins/wireguard/wireguard_noise.h
@@ -199,22 +199,22 @@
static_always_inline noise_keypair_t *
wg_get_active_keypair (noise_remote_t *r, uint32_t r_idx)
{
- if (r->r_current != NULL && r->r_current->kp_local_index == r_idx)
+ if (r->r_current != NULL)
{
- return r->r_current;
+ if (r->r_current->kp_local_index == r_idx)
+ return r->r_current;
}
- else if (r->r_previous != NULL && r->r_previous->kp_local_index == r_idx)
+ if (r->r_previous != NULL)
{
- return r->r_previous;
+ if (r->r_previous->kp_local_index == r_idx)
+ return r->r_previous;
}
- else if (r->r_next != NULL && r->r_next->kp_local_index == r_idx)
+ if (r->r_next != NULL)
{
- return r->r_next;
+ if (r->r_next->kp_local_index == r_idx)
+ return r->r_next;
}
- else
- {
- return NULL;
- }
+ return NULL;
}
inline bool