Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix ipv6 extension headers parsing #211

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading