aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-10-27 17:02:47 +0200
committerMatthew Smith <mgsmith@netgate.com>2021-10-28 12:58:31 +0000
commit48c0534c2eafe23fe8efba8c913109f30f6a294c (patch)
treea5d6b4944cf9674c475295c8eb3d8d2edb26205a
parent2b716b186fdfe0a40d6ddb9e43c795bb05d1ca10 (diff)
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
-rw-r--r--src/plugins/vrrp/vrrp_packet.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/plugins/vrrp/vrrp_packet.c b/src/plugins/vrrp/vrrp_packet.c
index 84bd3701edb..89a6ede605e 100644
--- a/src/plugins/vrrp/vrrp_packet.c
+++ b/src/plugins/vrrp/vrrp_packet.c
@@ -115,6 +115,10 @@ vrrp_adv_l3_build (vrrp_vr_t * vr, vlib_buffer_t * b,
* 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 @@ vrrp_adv_send (vrrp_vr_t * vr, int shutdown)
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 @@ static const ip4_header_t igmp_ip4_mcast = {
.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 @@ vrrp_igmp_pkt_build (vrrp_vr_t * vr, vlib_buffer_t * b)
/* 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 @@ vrrp_igmp_pkt_build (vrrp_vr_t * vr, vlib_buffer_t * b)
~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 @@ vrrp_vr_multicast_group_join (vrrp_vr_t * vr)
}
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;
}