diff --git a/libnetutil/PacketParser.cc b/libnetutil/PacketParser.cc index 73758712b..67af40b17 100644 --- a/libnetutil/PacketParser.cc +++ b/libnetutil/PacketParser.cc @@ -1126,24 +1126,28 @@ bool PacketParser::is_response(PacketElement *sent, PacketElement *rcvd){ /* So far we've verified that the ICMP error contains an IP datagram that matches * what we sent. Now, let's find the upper layer ICMP header (skip extension * headers until we find ICMP) */ - ICMPHeader *inner_icmp=(ICMPHeader *)iperror->getNextElement(); - while(inner_icmp!=NULL){ - if(inner_icmp->protocol_id()==HEADER_TYPE_ICMPv4 || inner_icmp->protocol_id()==HEADER_TYPE_ICMPv6 ){ + + iperror = dynamic_cast(iperror->getNextElement()); + while(iperror!=NULL){ + if(iperror->protocol_id()==HEADER_TYPE_ICMPv4 || iperror->protocol_id()==HEADER_TYPE_ICMPv6 ){ break; }else{ - inner_icmp=(ICMPHeader *)inner_icmp->getNextElement(); + iperror = dynamic_cast(iperror->getNextElement()); } } - if(inner_icmp==NULL) + if(iperror==NULL) return false; /* If we get here it means that we've found an ICMP header inside the * ICMP error message that we received. First of all, check that the * ICMP version matches what we sent. */ - if(sent_layer4->protocol_id() != inner_icmp->protocol_id()) + if(sent_layer4->protocol_id() != iperror->protocol_id()) return false; /* Make sure ICMP type and code match */ + ICMPHeader *inner_icmp = dynamic_cast(iperror); + if (inner_icmp == NULL) + return false; if( ((ICMPHeader*)sent_layer4)->getType() != inner_icmp->getType() ) return false; if( ((ICMPHeader*)sent_layer4)->getCode() != inner_icmp->getCode() )