Fix array bound failure in api_sr_localsid_add_del 70/14570/2
authorLijian Zhang <Lijian.Zhang@arm.com>
Tue, 28 Aug 2018 02:18:24 +0000 (10:18 +0800)
committerDamjan Marion <dmarion@me.com>
Thu, 30 Aug 2018 10:18:38 +0000 (10:18 +0000)
When compiling VPP with GCC-8.2.0, it gives below error messages.

src/vat/api_format.c: In function ‘api_sr_localsid_add_del’:
src/vat/api_format.c:10839:7: error: ‘memcpy’ forming offset [5, 16] is out of the bounds [0, 4] of object ‘nh_addr4’ with type ‘ip4_address_t’ {aka ‘union <anonymous>’} [-Werror=array-bounds]
       clib_memcpy (mp->nh_addr6, &nh_addr4, sizeof (mp->nh_addr6));
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/vat/api_format.c:10809:17: note: ‘nh_addr4’ declared here
   ip4_address_t nh_addr4;
                 ^~~~~~~~

Change-Id: I9065a3407d53c1f91974b32381972c4edb45144c
Signed-off-by: Lijian Zhang <Lijian.Zhang@arm.com>
src/vat/api_format.c

index 321127a..43b7d53 100644 (file)
@@ -10836,8 +10836,8 @@ api_sr_localsid_add_del (vat_main_t * vam)
   clib_memcpy (mp->localsid.addr, &localsid, sizeof (mp->localsid));
   if (nexthop_set)
     {
-      clib_memcpy (mp->nh_addr6, &nh_addr4, sizeof (mp->nh_addr6));
-      clib_memcpy (mp->nh_addr4, &nh_addr6, sizeof (mp->nh_addr4));
+      clib_memcpy (mp->nh_addr6, &nh_addr6, sizeof (mp->nh_addr6));
+      clib_memcpy (mp->nh_addr4, &nh_addr4, sizeof (mp->nh_addr4));
     }
   mp->behavior = behavior;
   mp->sw_if_index = ntohl (sw_if_index);