Skip to content

Commit a69b0d5

Browse files
committed
IPv6: Report some invalid packets as invalid, not truncated
When the (original) length is < length of the header, output example: [length 39 < 40] (invalid) (The IPv6 header must be 40 bytes in length.) Place the 'length' test before the 'version' test. Add a test file.
1 parent 74f5a0e commit a69b0d5

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

print-ip6.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,13 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
246246
ND_PRINT(" ");
247247
}
248248

249+
ND_ICHECK_ZU(length, <, sizeof (struct ip6_hdr));
249250
if (IP6_VERSION(ip6) != 6) {
250251
ND_PRINT("version error: %u != 6", IP6_VERSION(ip6));
251252
return;
252253
}
253254

254255
ND_TCHECK_SIZE(ip6);
255-
if (length < sizeof (struct ip6_hdr)) {
256-
ND_PRINT("truncated-ip6 %u", length);
257-
return;
258-
}
259-
260256
payload_len = GET_BE_U_2(ip6->ip6_plen);
261257
/*
262258
* RFC 1883 says:
@@ -501,4 +497,8 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
501497
return;
502498
trunc:
503499
nd_print_trunc(ndo);
500+
return;
501+
502+
invalid:
503+
nd_print_invalid(ndo);
504504
}

tests/TESTLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ ipv6-srh-tlv-hmac ipv6-srh-tlv-hmac.pcap ipv6-srh-tlv-hmac.out
359359
ipv6-srh-tlv-hmac-v ipv6-srh-tlv-hmac.pcap ipv6-srh-tlv-hmac-v.out -v
360360
ipv6-srh-tlv-pad1-padn-5 ipv6-srh-tlv-pad1-padn-5.pcap ipv6-srh-tlv-pad1-padn-5.out
361361
ipv6-srh-tlv-pad1-padn-5-v ipv6-srh-tlv-pad1-padn-5.pcap ipv6-srh-tlv-pad1-padn-5-v.out -v
362+
ipv6_invalid_length ipv6_invalid_length.pcap ipv6_invalid_length.out
362363

363364
# Loopback/CTP test case
364365
loopback loopback.pcap loopback.out

tests/ipv6_invalid_length.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 09:18:26.706088 IP6 [length 39 < 40] (invalid)

tests/ipv6_invalid_length.pcap

93 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)