Skip to content

Commit 4966c76

Browse files
committed
frag6: Fix invalid 32-bit versus 64-bit printouts
Print "[length < 0] (invalid)" when fragment length is negative. In this case, e.g. when IPv6 payload length is zero, the 32-bit and 64-bit printouts were different. Example: 32-bit: frag (0x80000074:1280|4294967288) --- 64-bit: frag (0x80000074:1280|18446744073709551608) Add a test file. (cherry picked from commit 067f7dd)
1 parent efe1c57 commit 4966c76

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

print-frag6.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ frag6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2)
4545
ND_PRINT("frag (");
4646
if (ndo->ndo_vflag)
4747
ND_PRINT("0x%08x:", GET_BE_U_4(dp->ip6f_ident));
48-
ND_PRINT("%u|%zu)",
49-
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
50-
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
51-
(bp - bp2) - sizeof(struct ip6_frag));
48+
ND_PRINT("%u|", GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK);
49+
if ((bp - bp2) + sizeof(struct ip6_frag) >
50+
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen))
51+
ND_PRINT("[length < 0] (invalid))");
52+
else
53+
ND_PRINT("%zu)",
54+
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
55+
(bp - bp2) - sizeof(struct ip6_frag));
5256

5357
/* it is meaningless to decode non-first fragment */
5458
if ((GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK) != 0)

tests/TESTLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ ipv6_invalid_length_2 ipv6_invalid_length_2.pcap ipv6_invalid_length_2.out -v
327327
ipv6_jumbogram_invalid_length ipv6_jumbogram_invalid_length.pcap ipv6_jumbogram_invalid_length.out -v
328328
ipv6_39_byte_header ipv6_39_byte_header.pcap ipv6_39_byte_header.out -v
329329
ipv6_missing_jumbo_payload_option ipv6_missing_jumbo_payload_option.pcap ipv6_missing_jumbo_payload_option.out
330+
ipv6_frag6_negative_len ipv6_frag6_negative_len.pcap ipv6_frag6_negative_len.out -v
330331

331332
# Loopback/CTP test case
332333
loopback loopback.pcap loopback.out

tests/ipv6_frag6_negative_len.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 1975-11-02 10:29:20.131862 IP6 (class 0x50, flowlabel 0x00073, hlim 28, next-header Fragment (44) payload length: 0) 7fff:ffff:c3b2:a102:1305:80:38:2949 > 9675:86dd:7300:2c:1c7f:ffff:ffc3:b2a1: frag (0x80000074:1280|[length < 0] (invalid))

tests/ipv6_frag6_negative_len.pcap

110 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)