vrrp: fix coverity warning/NULL dereference

Add error handling for unlikely case where getting IP address of an
interface fails.

Type: fix
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: Ief8642af79fb1d25f061357cd716b93cfdf23fc8
diff --git a/src/plugins/vrrp/vrrp_packet.c b/src/plugins/vrrp/vrrp_packet.c
index 84bd370..89a6ede 100644
--- a/src/plugins/vrrp/vrrp_packet.c
+++ b/src/plugins/vrrp/vrrp_packet.c
@@ -115,6 +115,10 @@
        * this is the first address on the interface.
        */
       src4 = ip_interface_get_first_ip (vr->config.sw_if_index, 1);
+      if (!src4)
+	{
+	  return -1;
+	}
       ip4->src_address.as_u32 = src4->as_u32;
       ip4->length = clib_host_to_net_u16 (sizeof (*ip4) +
 					  vrrp_adv_payload_len (vr));
@@ -332,7 +336,13 @@
       else
 	vrrp_adv_l2_build_multicast (vr, b);
 
-      vrrp_adv_l3_build (vr, b, dst);
+      if (-1 == vrrp_adv_l3_build (vr, b, dst))
+	{
+	  vlib_frame_free (vm, vlib_node_get_runtime (vm, node_index),
+			   to_frame);
+	  vlib_buffer_free (vm, bi, n_buffers);
+	  return -1;
+	}
       vrrp_adv_payload_build (vr, b, shutdown);
 
       vlib_buffer_reset (b);
@@ -536,8 +546,8 @@
   .dst_address = {.as_u8 = IGMP4_MCAST_ADDR_AS_U8,},
 };
 
-static void
-vrrp_igmp_pkt_build (vrrp_vr_t * vr, vlib_buffer_t * b)
+static int
+vrrp_igmp_pkt_build (vrrp_vr_t *vr, vlib_buffer_t *b)
 {
   ip4_header_t *ip4;
   u8 *ip4_options;
@@ -550,6 +560,10 @@
 
   /* Use the source address advertisements will use to join mcast group */
   src4 = ip_interface_get_first_ip (vr->config.sw_if_index, 1);
+  if (!src4)
+    {
+      return -1;
+    }
   ip4->src_address.as_u32 = src4->as_u32;
 
   vlib_buffer_chain_increase_length (b, b, sizeof (*ip4));
@@ -592,6 +606,7 @@
     ~ip_csum_fold (ip_incremental_checksum (0, report, payload_len));
 
   vlib_buffer_reset (b);
+  return 0;
 }
 
 /* multicast listener report packet format for ethernet. */
@@ -731,7 +746,13 @@
     }
   else
     {
-      vrrp_igmp_pkt_build (vr, b);
+      if (-1 == vrrp_igmp_pkt_build (vr, b))
+	{
+	  clib_warning ("IGMP packet build failed for %U", format_vrrp_vr_key,
+			vr);
+	  vlib_buffer_free (vm, &bi, 1);
+	  return -1;
+	}
       node_index = ip4_rewrite_mcast_node.index;
     }