ipsec: make sure pad_bytes does not exceed pad data size 63/23863/2
authorBenoît Ganne <bganne@cisco.com>
Sat, 7 Dec 2019 16:14:27 +0000 (09:14 -0700)
committerDave Barach <openvpp@barachs.net>
Mon, 9 Dec 2019 15:49:31 +0000 (15:49 +0000)
This helps GCC understand the memcpy will not overflow pad_data. GCC-6
(default on Debian 9) in particular got confused.

Type: fix

Change-Id: I176eb01531b9d5c7ebec40f015e510b2d56e77c4
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/vnet/ipsec/esp_encrypt.c

index 186e122..6170603 100644 (file)
@@ -114,7 +114,11 @@ esp_add_footer_and_icv (vlib_buffer_t * b, u8 block_size, u8 icv_sz,
     }
 
   if (pad_bytes)
-    clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, pad_bytes);
+    {
+      ASSERT (pad_bytes <= ESP_MAX_BLOCK_SIZE);
+      pad_bytes = clib_min (ESP_MAX_BLOCK_SIZE, pad_bytes);
+      clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, pad_bytes);
+    }
 
   f->pad_length = pad_bytes;
   b->current_length = new_length + icv_sz;