summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIdo Barnea <ibarnea@cisco.com>2016-03-28 10:10:32 +0300
committerIdo Barnea <ibarnea@cisco.com>2016-03-28 10:10:32 +0300
commitdd5fb4a71be0964d9a904af02b4010d87f28f66b (patch)
tree39c13cef15c2600341829d3e4e904e5073c73660
parent68ed79b989008006897108c7978d5c65fef47711 (diff)
fix valgrind faiulre. Read memory of too short packet
-rwxr-xr-xsrc/common/Network/Packet/EthernetHeader.h3
-rw-r--r--src/flow_stat_parser.cpp20
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: