vrrp: fix coverity errors 26/25326/2
authorMatthew Smith <mgsmith@netgate.com>
Thu, 20 Feb 2020 14:58:15 +0000 (08:58 -0600)
committerNeale Ranns <nranns@cisco.com>
Fri, 21 Feb 2020 08:53:57 +0000 (08:53 +0000)
Type: fix
Fixes: 39e9428b90

Fix warnings about potential problems with an implicit type cast
and a null pointer dereference.

Change-Id: I8c8d220e79ba45b62ba783cfe53cb49eef175fc8
Signed-off-by: Matthew Smith <mgsmith@netgate.com>
src/plugins/vrrp/node.c
src/plugins/vrrp/vrrp_packet.c

index 34d082e..3355198 100644 (file)
@@ -662,12 +662,13 @@ vrrp_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       if (b0->flags & VLIB_BUFFER_IS_TRACED)
        {
          vrrp_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
+         size_t addr_len = (is_ipv6 ? 16 : 4);
 
          t->sw_if_index = vnet_buffer(b0)->sw_if_index[VLIB_RX];
          t->is_ipv6 = is_ipv6;
          clib_memcpy_fast (&t->vrrp, vrrp0, sizeof (*vrrp0));
          clib_memcpy_fast (t->addrs, (void *) (vrrp0 + 1),
-                           vrrp0->n_addrs * (is_ipv6 ? 16 : 4));
+                           (size_t) vrrp0->n_addrs * addr_len);
        }
 
       /* always drop, never forward or reply here */
index f624b18..6b0d4c9 100644 (file)
@@ -282,6 +282,16 @@ vrrp_adv_send (vrrp_vr_t * vr, int shutdown)
   if (is_unicast)
     n_buffers = vec_len (vr->config.peer_addrs);
 
+  if (n_buffers < 1)
+    {
+      /* A unicast VR will not start without peers added so this should
+       * not happen. Just avoiding a crash if it happened somehow.
+       */
+      clib_warning ("Unicast VR configuration corrupted for %U",
+                   format_vrrp_vr_key, vr);
+      return -1;
+    }
+
   vec_validate (bi, n_buffers - 1);
   if (vlib_buffer_alloc (vm, bi, n_buffers) != n_buffers)
     {