Coverity errors in MPLS code 77/4077/2
authorNeale Ranns <nranns@cisco.com>
Fri, 2 Dec 2016 15:41:03 +0000 (15:41 +0000)
committerDamjan Marion <dmarion.lists@gmail.com>
Fri, 2 Dec 2016 20:52:56 +0000 (20:52 +0000)
Change-Id: I3f98e3c30e29198cb8701bfb846ce194b7250ed7
Signed-off-by: Neale Ranns <nranns@cisco.com>
vnet/vnet/mpls/mpls_tunnel.c
vpp/vpp-api/api.c

index 6ad11e3..8d1e30a 100644 (file)
@@ -104,7 +104,12 @@ mpls_tunnel_build_rewrite (vnet_main_t * vnm,
     mti = mpls_tunnel_db[sw_if_index];
     mt = pool_elt_at_index(mpls_tunnel_pool, mti);
 
+    /*
+     * The vector must be allocated as u8 so the length is correct
+     */
+    ASSERT(0 < vec_len(mt->mt_label_stack));
     vec_validate(rewrite, (sizeof(*muh) * vec_len(mt->mt_label_stack)) - 1);
+    ASSERT(rewrite);
     muh = (mpls_unicast_header_t *)rewrite;
 
     /*
@@ -123,15 +128,19 @@ mpls_tunnel_build_rewrite (vnet_main_t * vnm,
     vnet_mpls_uc_set_ttl(&muh[ii].label_exp_s_ttl, 255);
     vnet_mpls_uc_set_exp(&muh[ii].label_exp_s_ttl, 0);
 
-    if (VNET_LINK_MPLS == link_type &&
-       mt->mt_label_stack[ii] != MPLS_IETF_IMPLICIT_NULL_LABEL)
+    if ((VNET_LINK_MPLS == link_type) &&
+       (mt->mt_label_stack[ii] != MPLS_IETF_IMPLICIT_NULL_LABEL))
+    {
        vnet_mpls_uc_set_s(&muh[ii].label_exp_s_ttl, MPLS_NON_EOS);
+    }
     else
+    {
        vnet_mpls_uc_set_s(&muh[ii].label_exp_s_ttl, MPLS_EOS);
+    }
 
     muh[ii].label_exp_s_ttl = clib_host_to_net_u32(muh[ii].label_exp_s_ttl);
 
-    return ((u8*)muh);
+    return (rewrite);
 }
 
 /**
index c110769..b778d3c 100644 (file)
@@ -2149,7 +2149,8 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
     }
   else
     {
-      vnet_mpls_tunnel_del (ntohl (mp->mt_sw_if_index));
+      tunnel_sw_if_index = ntohl (mp->mt_sw_if_index);
+      vnet_mpls_tunnel_del (tunnel_sw_if_index);
     }
 
   dsunlock (sm);