Skip to content

Commit

Permalink
Bug #827 PR# 842: add check for IPv6 extension header length
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen committed Jun 1, 2024
1 parent 77f02cb commit 5b56443
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
09/03/2023 Version 4.5.0-beta1
06/01/2024 Version 4.5.0-beta1
- add check for IPv6 extension header length (#827 #842)
- GitHub template for pull requests (#839)
- handle IPv6 fragment extension header (#832 #837)
- configure.ac: unify search dirs for pcap and add lib32 (#819)
Expand Down
29 changes: 21 additions & 8 deletions src/common/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extern const char pcap_version[];
static void *get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const u_char *end_ptr);

/**
* Depending on what version of libpcap/WinPcap there are different ways to get
* the version of the libpcap/WinPcap library. This presents a unified way to
* Depending on what version of libpcap there are different ways to get
* the version of the libpcap library. This presents a unified way to
* get that information.
*/
const char *
Expand Down Expand Up @@ -196,27 +196,38 @@ parse_metadata(const u_char *pktdata,
uint32_t *vlan_offset)
{
bool done = false;
int res = 0;
while (!done && res == 0) {
assert(next_protocol);
assert(l2len);
assert(l2offset);
assert(vlan_offset);

if (!pktdata || !datalen)

Check warning on line 204 in src/common/get.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/get.c:204:30 [readability-braces-around-statements]

statement should be inside braces
errx(-1, "parse_metadata: invalid L2 parameters: pktdata=0x%p len=%d", pktdata, datalen);

while (!done) {
switch (*next_protocol) {
case ETHERTYPE_VLAN:
case ETHERTYPE_Q_IN_Q:
case ETHERTYPE_8021QINQ:
if (*vlan_offset == 0)
*vlan_offset = *l2len;

res = parse_vlan(pktdata, datalen, next_protocol, l2len);
if (parse_vlan(pktdata, datalen, next_protocol, l2len))

Check warning on line 215 in src/common/get.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/get.c:215:68 [readability-braces-around-statements]

statement should be inside braces
return -1;

break;
case ETHERTYPE_MPLS:
case ETHERTYPE_MPLS_MULTI:
res = parse_mpls(pktdata, datalen, next_protocol, l2len, l2offset);
if (parse_mpls(pktdata, datalen, next_protocol, l2len, l2offset))

Check warning on line 221 in src/common/get.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/get.c:221:78 [readability-braces-around-statements]

statement should be inside braces
return -1;

break;
default:
done = true;
}
}

return res;
return 0;
}

/*
Expand Down Expand Up @@ -629,9 +640,11 @@ get_layer4_v6(const ipv6_hdr_t *ip6_hdr, const u_char *end_ptr)
* no further processing, either TCP, UDP, ICMP, etc...
*/
default:
if (proto != ip6_hdr->ip_nh) {
if (proto != ip6_hdr->ip_nh && next) {
dbgx(3, "Returning byte offset of this ext header: %u", IPV6_EXTLEN_TO_BYTES(next->ip_len));
next = (void *)((u_char *)next + IPV6_EXTLEN_TO_BYTES(next->ip_len));
if ((u_char*)next > end_ptr)

Check warning on line 646 in src/common/get.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/get.c:646:45 [readability-braces-around-statements]

statement should be inside braces
return NULL;
} else {
dbgx(3, "%s", "Returning end of IPv6 Header");
}
Expand Down

0 comments on commit 5b56443

Please sign in to comment.