Skip to content

Commit 4be259b

Browse files
authored
Merge pull request #211 from Zadamsa/fix-ipv6-header-parsing
Fix ipv6 extension headers parsing
2 parents b624c78 + a3a5131 commit 4be259b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

input/parser.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <cstring>
3232
#include <iostream>
3333
#include <sys/types.h>
34+
#include <limits>
3435

3536
#include "parser.hpp"
3637
#include "headers.hpp"
@@ -352,7 +353,7 @@ uint16_t skip_ipv6_ext_hdrs(const u_char *data_ptr, uint16_t data_len, Packet *p
352353
{
353354
struct ip6_ext *ext = (struct ip6_ext *) data_ptr;
354355
uint8_t next_hdr = pkt->ip_proto;
355-
uint16_t hdrs_len = 0;
356+
uint32_t hdrs_len = 0;
356357

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

391394
next_hdr = ext->ip6e_nxt;
392395
ext = (struct ip6_ext *) (data_ptr + hdrs_len);
393396
pkt->ip_proto = next_hdr;
394397
}
395-
398+
if (hdrs_len > std::numeric_limits<uint16_t>::max())
399+
throw "Parser detected malformed packet";
396400
pkt->ip_payload_len -= hdrs_len;
397401
return hdrs_len;
398402
}

0 commit comments

Comments
 (0)