aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2017-08-30 10:47:45 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-09-04 22:56:50 +0300
commit42184679185ce0c979e065349360167e3fce6ca0 (patch)
treedd145691151e4c5392fdba82e5e14c0e4677eed8 /helper
parent120e914768f731f18083afd950fba6a6793cca45 (diff)
helper: chksum: add few guarding conditions
Add few guarding conditions, otherwise bad packet can hang up ODP code. Noted by one of the corner case tests for IPsec. Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'helper')
-rw-r--r--helper/include/odp/helper/ip.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h
index e0d5c3bfb..fb7e5ddce 100644
--- a/helper/include/odp/helper/ip.h
+++ b/helper/include/odp/helper/ip.h
@@ -100,10 +100,12 @@ static inline int odph_ipv4_csum(odp_packet_t pkt,
odph_ipv4hdr_t *ip,
odp_u16sum_t *chksum)
{
- int nleft = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4;
+ unsigned nleft = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4;
uint16_t buf[nleft / 2];
int res;
+ if (odp_unlikely(nleft < sizeof(*ip)))
+ return -1;
ip->chksum = 0;
memcpy(buf, ip, sizeof(*ip));
res = odp_packet_copy_to_mem(pkt, offset + sizeof(*ip),
@@ -135,7 +137,9 @@ static inline int odph_ipv4_csum_valid(odp_packet_t pkt)
if (offset == ODP_PACKET_OFFSET_INVALID)
return 0;
- odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);
+ res = odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);
+ if (odp_unlikely(res < 0))
+ return 0;
chksum = ip.chksum;