summaryrefslogtreecommitdiffstats
path: root/src/flow_stat_parser.cpp
diff options
context:
space:
mode:
authorIdo Barnea <ibarnea@cisco.com>2016-03-27 14:27:58 +0300
committerIdo Barnea <ibarnea@cisco.com>2016-03-27 17:18:30 +0300
commit9b35a803e4bb42189ab75766af799341379bfc61 (patch)
tree18101f57c266a3e9b2b6214095861a143d45895a /src/flow_stat_parser.cpp
parent0f848ef47ab8490591387971c15c88ba89b19117 (diff)
Protecting against too short packets in flow stat parser. This caused valgrind test to fail.
Diffstat (limited to 'src/flow_stat_parser.cpp')
-rw-r--r--src/flow_stat_parser.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/flow_stat_parser.cpp b/src/flow_stat_parser.cpp
index 8a77c82d..53aa650e 100644
--- a/src/flow_stat_parser.cpp
+++ b/src/flow_stat_parser.cpp
@@ -33,15 +33,21 @@ void CFlowStatParser::reset() {
int CFlowStatParser::parse(uint8_t *p, uint16_t len) {
EthernetHeader *ether = (EthernetHeader *)p;
+ int min_len = 14 + IPV4_HDR_LEN;
reset();
switch( ether->getNextProtocol() ) {
case EthernetHeader::Protocol::IP :
+ if (len < min_len)
+ return -1;
m_ipv4 = (IPHeader *)(p + 14);
m_stat_supported = true;
break;
case EthernetHeader::Protocol::VLAN :
+ min_len += 4;
+ if (len < min_len)
+ return -1;
switch ( ether->getVlanProtocol() ){
case EthernetHeader::Protocol::IP:
m_ipv4 = (IPHeader *)(p + 18);
@@ -137,11 +143,14 @@ 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;
reset();
switch( ether->getNextProtocol() ) {
case EthernetHeader::Protocol::IP :
+ if (len < min_len)
+ return -1;
m_ipv4 = (IPHeader *)(p + 14);
m_stat_supported = true;
break;