Coverity fixes (VPP-1204) 62/11462/2
authorChris Luke <chrisy@flirble.org>
Thu, 29 Mar 2018 19:56:58 +0000 (12:56 -0700)
committerChris Luke <chrisy@flirble.org>
Thu, 29 Mar 2018 22:23:56 +0000 (15:23 -0700)
Minor bug fixes

CID 183000: double close
CID 180996: dead code
CID 180995: NULL deref
CID 181957: NULL deref
CID 182676: NULL deref
CID 182675: NULL deref

Change-Id: Id35e391c95fafb8cd771984ee8a1a6e597056d37
Signed-off-by: Chris Luke <chrisy@flirble.org>
src/vlib/linux/pci.c
src/vnet/ip/ip4_reassembly.c
src/vnet/ip/ip6_reassembly.c
src/vnet/ip/ip_api.c
src/vnet/srmpls/sr_mpls_policy.c
src/vnet/srmpls/sr_mpls_steering.c

index 127d2ef..11480ca 100644 (file)
@@ -919,8 +919,9 @@ error:
     {
       if (p->fd != -1)
        close (p->fd);
-      if (p->config_fd != -1)
+      if (p->config_fd != -1 && p->config_fd != p->fd)
        close (p->config_fd);
+      p->config_fd = p->fd = -1;
     }
   return err;
 }
index 114d8e0..b94a258 100644 (file)
@@ -497,6 +497,8 @@ ip4_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
        reass.next_range_bi;
     }
   while (~0 != sub_chain_bi);
+
+  ASSERT (last_b != NULL);
   last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
   ASSERT (rt->buffers_n >= (buf_cnt - dropped_cnt));
   rt->buffers_n -= buf_cnt - dropped_cnt;
index c6424a7..1be5b5e 100644 (file)
@@ -534,6 +534,8 @@ ip6_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
        reass.next_range_bi;
     }
   while (~0 != sub_chain_bi);
+
+  ASSERT (last_b != NULL);
   last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
   vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi);
   ASSERT (total_length >= first_b->current_length);
index a8dbb3a..0b0a7a9 100644 (file)
@@ -2253,6 +2253,7 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
             ({
              vl_api_registration_t *vl_reg;
               vl_reg = vl_api_client_index_to_registration (reg->client_index);
+              ASSERT (vl_reg != NULL);
              if (reg && vl_api_can_send_msg (vl_reg))
                {
                  vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
index 4a56324..7d336c1 100755 (executable)
@@ -661,6 +661,10 @@ sr_mpls_policy_assign_endpoint_color (mpls_label_t bsid,
       old_value =
        mhash_get ((mhash_t *) endpoint_table, &sr_policy->endpoint);
 
+      /* CID 180995 This should never be NULL unless the two hash tables
+       * get out of sync */
+      ASSERT (old_value != NULL);
+
       fib_prefix_t pfx = { 0 };
       pfx.fp_proto = FIB_PROTOCOL_MPLS;
       pfx.fp_len = 21;
index 8bb072c..c5ddab7 100755 (executable)
@@ -393,22 +393,16 @@ sr_mpls_steering_policy_add (mpls_label_t bsid, u32 table_id,
 
   memset (&key, 0, sizeof (sr_mpls_steering_key_t));
 
-  /* Compute the steer policy key */
-  if (traffic_type == SR_STEER_IPV4 || traffic_type == SR_STEER_IPV6)
-    {
-      key.prefix.as_u64[0] = prefix->as_u64[0];
-      key.prefix.as_u64[1] = prefix->as_u64[1];
-      key.mask_width = mask_width;
-      key.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
-    }
-  else
+  if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6)
     return -1;
 
+  /* Compute the steer policy key */
+  key.prefix.as_u64[0] = prefix->as_u64[0];
+  key.prefix.as_u64[1] = prefix->as_u64[1];
+  key.mask_width = mask_width;
+  key.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
   key.traffic_type = traffic_type;
 
-  if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6)
-    return -1;
-
   /*
    * Search for steering policy. If already exists we are adding a new
    * color.