From dd5fb4a71be0964d9a904af02b4010d87f28f66b Mon Sep 17 00:00:00 2001 From: Ido Barnea Date: Mon, 28 Mar 2016 10:10:32 +0300 Subject: fix valgrind faiulre. Read memory of too short packet --- src/common/Network/Packet/EthernetHeader.h | 3 ++- src/flow_stat_parser.cpp | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/common/Network/Packet/EthernetHeader.h b/src/common/Network/Packet/EthernetHeader.h index 87d1ed91..c9dcdbe2 100755 --- a/src/common/Network/Packet/EthernetHeader.h +++ b/src/common/Network/Packet/EthernetHeader.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2015 Cisco Systems, Inc. +Copyright (c) 2015-2016 Cisco Systems, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ limitations under the License. #include "PacketHeaderBase.h" #include "MacAddress.h" +#define ETH_HDR_LEN 14 /** * This class encapsulates an ethernet header. diff --git a/src/flow_stat_parser.cpp b/src/flow_stat_parser.cpp index 53aa650e..200c19c9 100644 --- a/src/flow_stat_parser.cpp +++ b/src/flow_stat_parser.cpp @@ -33,15 +33,15 @@ void CFlowStatParser::reset() { int CFlowStatParser::parse(uint8_t *p, uint16_t len) { EthernetHeader *ether = (EthernetHeader *)p; - int min_len = 14 + IPV4_HDR_LEN; - + int min_len = ETH_HDR_LEN + IPV4_HDR_LEN; reset(); + if (len < min_len) + return -1; + switch( ether->getNextProtocol() ) { case EthernetHeader::Protocol::IP : - if (len < min_len) - return -1; - m_ipv4 = (IPHeader *)(p + 14); + m_ipv4 = (IPHeader *)(p + ETH_HDR_LEN); m_stat_supported = true; break; case EthernetHeader::Protocol::VLAN : @@ -143,15 +143,15 @@ int CFlowStatParser::test() { // In 82599 10G card we do not support VLANs int C82599Parser::parse(uint8_t *p, uint16_t len) { EthernetHeader *ether = (EthernetHeader *)p; - int min_len = 14 + IPV4_HDR_LEN; - + int min_len = ETH_HDR_LEN + IPV4_HDR_LEN; reset(); + if (len < min_len) + return -1; + switch( ether->getNextProtocol() ) { case EthernetHeader::Protocol::IP : - if (len < min_len) - return -1; - m_ipv4 = (IPHeader *)(p + 14); + m_ipv4 = (IPHeader *)(p + ETH_HDR_LEN); m_stat_supported = true; break; default: -- cgit 1.2.3-korg