From ab80e474f26f2e982bc15dd2506ff2eeef129dcc Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 19 Jan 2023 10:32:18 -0300 Subject: [PATCH 1/2] zebra: fix possible null dereference Don't attempt to dereference `ifp` directly if it might be null: there is a check right before this usage: `ifp ? ifp->info : NULL`. In this context it should be safe to assume `ifp` is not NULL because the only caller of this function checks that for this `ifindex`. For consistency we'll check for null anyway in case this ever changes (and with this the coverity scan warning gets silenced). Found by Coverity Scan (CID 1519776) Signed-off-by: Rafael Zalamena --- zebra/interface.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zebra/interface.c b/zebra/interface.c index 87bb49042a..59563834ef 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1436,7 +1436,8 @@ static void zebra_if_netconf_update_ctx(struct zebra_dplane_ctx *ctx, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "%s: if %s(%u) zebra info pointer is NULL", - __func__, ifp->name, ifp->ifindex); + __func__, ifp ? ifp->name : "(null)", + ifp ? ifp->ifindex : ifindex); return; } if (afi == AFI_IP) { From ff9232c83bad982838e68fc0f9b7fbe8f77e0e02 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 19 Jan 2023 10:42:01 -0300 Subject: [PATCH 2/2] lib: remove dead logic code If we got inside the condition of `vrfp->status == VRF_ACTIVE` then don't make the same check again. Found by Coverity Scan (CID 1519760) Signed-off-by: Rafael Zalamena --- lib/vrf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/vrf.c b/lib/vrf.c index 5878c1734f..2ac7ef7a97 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -1000,8 +1000,7 @@ lib_vrf_state_active_get_elem(struct nb_cb_get_elem_args *args) struct vrf *vrfp = (struct vrf *)args->list_entry; if (vrfp->status == VRF_ACTIVE) - return yang_data_new_bool( - args->xpath, vrfp->status == VRF_ACTIVE ? true : false); + return yang_data_new_bool(args->xpath, true); return NULL; }