vrrp: fix api-related coverity warnings 45/25545/2
authorDave Barach <dave@barachs.net>
Fri, 28 Feb 2020 14:27:07 +0000 (09:27 -0500)
committerFlorin Coras <florin.coras@gmail.com>
Fri, 28 Feb 2020 15:33:40 +0000 (15:33 +0000)
Type: fix
Ticket: VPP-1837

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I13c0e4771defaebccc976a6f6703493de29434dd

src/plugins/vrrp/vrrp_api.c
src/plugins/vrrp/vrrp_test.c

index d2badc0..9ef9020 100644 (file)
@@ -34,6 +34,8 @@ vl_api_vrrp_vr_add_del_t_handler (vl_api_vrrp_vr_add_del_t * mp)
   ip46_address_t *addrs = 0;
   int rv;
 
+  VALIDATE_SW_IF_INDEX (mp);
+
   api_flags = htonl (mp->flags);
 
   clib_memset (&vr_conf, 0, sizeof (vr_conf));
@@ -106,6 +108,7 @@ vl_api_vrrp_vr_add_del_t_handler (vl_api_vrrp_vr_add_del_t * mp)
 
   vec_free (addrs);
 
+  BAD_SW_IF_INDEX_LABEL;
   REPLY_MACRO (VL_API_VRRP_VR_ADD_DEL_REPLY);
 }
 
index 89ad712..eaa0c40 100644 (file)
@@ -227,12 +227,19 @@ vl_api_vrrp_vr_details_t_handler (vl_api_vrrp_vr_details_t * mp)
   vat_main_t *vam = vrrp_test_main.vat_main;
   u32 api_flags = ntohl (mp->config.flags);
   int i;
+  u32 state;
   char *states[] = {
     "VRRP_API_VR_STATE_INIT",
     "VRRP_API_VR_STATE_BACKUP",
     "VRRP_API_VR_STATE_MASTER",
+    "BAD STATE!",
   };
 
+  state = ntohl (mp->runtime.state);
+
+  if (state > ARRAY_LEN (states) - 2)
+    state = ARRAY_LEN (states) - 1;
+
   fformat (vam->ofp, "sw_if_index %u vr_id %u IPv%d: "
           "priority %u interval %u preempt %s accept %s unicast %s "
           "state %s master_adv_interval %u skew %u master_down_interval %u "
@@ -243,7 +250,7 @@ vl_api_vrrp_vr_details_t_handler (vl_api_vrrp_vr_details_t * mp)
           (api_flags & VRRP_API_VR_PREEMPT) ? "yes" : "no",
           (api_flags & VRRP_API_VR_ACCEPT) ? "yes" : "no",
           (api_flags & VRRP_API_VR_UNICAST) ? "yes" : "no",
-          states[ntohl (mp->runtime.state)],
+          states[state],
           ntohs (mp->runtime.master_adv_int), ntohs (mp->runtime.skew),
           ntohs (mp->runtime.master_down_int),
           format_ethernet_address, &mp->runtime.mac);