summaryrefslogtreecommitdiffstats
path: root/src/plugins/wireguard/wireguard_noise.h
diff options
context:
space:
mode:
authorGabriel Oginski <gabrielx.oginski@intel.com>2022-02-22 14:15:11 +0000
committerFan Zhang <roy.fan.zhang@intel.com>2022-02-23 09:15:12 +0000
commit45207e0fb2c46e211ff2e66fb141867d81198d97 (patch)
treeb1c49c364ceb666dfab8f9086395d9c62e829408 /src/plugins/wireguard/wireguard_noise.h
parenta7d7383a44335358a40d7c2b322999958a717a60 (diff)
wireguard: fix dereferences null pointer
Type: fix Fixed coverity-issue CID 248517. Originally possible passing null pointer to one function and directly dereferences it. This patch fixes the issue by add a new condition to check this pointer. Change-Id: If506abaf08c9f003860b641971af291f68613c18 Signed-off-by: Gabriel Oginski <gabrielx.oginski@intel.com>
Diffstat (limited to 'src/plugins/wireguard/wireguard_noise.h')
-rw-r--r--src/plugins/wireguard/wireguard_noise.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/plugins/wireguard/wireguard_noise.h b/src/plugins/wireguard/wireguard_noise.h
index b436120dd8c..e95211b8884 100644
--- a/src/plugins/wireguard/wireguard_noise.h
+++ b/src/plugins/wireguard/wireguard_noise.h
@@ -199,22 +199,22 @@ noise_remote_encrypt (vlib_main_t * vm, noise_remote_t *,
static_always_inline noise_keypair_t *
wg_get_active_keypair (noise_remote_t *r, uint32_t r_idx)
{
- if (r->r_current != NULL)
+ if (r->r_current != NULL && r->r_current->kp_local_index == r_idx)
{
- if (r->r_current->kp_local_index == r_idx)
- return r->r_current;
+ return r->r_current;
}
- if (r->r_previous != NULL)
+ else if (r->r_previous != NULL && r->r_previous->kp_local_index == r_idx)
{
- if (r->r_previous->kp_local_index == r_idx)
- return r->r_previous;
+ return r->r_previous;
}
- if (r->r_next != NULL)
+ else if (r->r_next != NULL && r->r_next->kp_local_index == r_idx)
{
- if (r->r_next->kp_local_index == r_idx)
- return r->r_next;
+ return r->r_next;
+ }
+ else
+ {
+ return NULL;
}
- return NULL;
}
inline bool