Skip to content

Commit

Permalink
Merge pull request #211 from Zadamsa/fix-ipv6-header-parsing
Browse files Browse the repository at this point in the history
Fix ipv6 extension headers parsing
  • Loading branch information
SiskaPavel authored Aug 19, 2024
2 parents b624c78 + a3a5131 commit 4be259b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions input/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <cstring>
#include <iostream>
#include <sys/types.h>
#include <limits>

#include "parser.hpp"
#include "headers.hpp"
Expand Down Expand Up @@ -352,7 +353,7 @@ uint16_t skip_ipv6_ext_hdrs(const u_char *data_ptr, uint16_t data_len, Packet *p
{
struct ip6_ext *ext = (struct ip6_ext *) data_ptr;
uint8_t next_hdr = pkt->ip_proto;
uint16_t hdrs_len = 0;
uint32_t hdrs_len = 0;

/* Skip/parse extension headers... */
while (1) {
Expand Down Expand Up @@ -385,14 +386,17 @@ uint16_t skip_ipv6_ext_hdrs(const u_char *data_ptr, uint16_t data_len, Packet *p
} else {
break;
}
if (hdrs_len > std::numeric_limits<uint16_t>::max())
throw "Parser detected malformed packet";
DEBUG_MSG("\tIPv6 extension header:\t%u\n", next_hdr);
DEBUG_MSG("\t\tLength:\t%u\n", ext->ip6e_len);

next_hdr = ext->ip6e_nxt;
ext = (struct ip6_ext *) (data_ptr + hdrs_len);
pkt->ip_proto = next_hdr;
}

if (hdrs_len > std::numeric_limits<uint16_t>::max())
throw "Parser detected malformed packet";
pkt->ip_payload_len -= hdrs_len;
return hdrs_len;
}
Expand Down

0 comments on commit 4be259b

Please # to comment.