Skip to content

Commit 067f7dd

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.
1 parent e5b1cab commit 067f7dd

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
@@ -43,10 +43,14 @@ frag6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2)
4343
ND_PRINT("frag (");
4444
if (ndo->ndo_vflag)
4545
ND_PRINT("0x%08x:", GET_BE_U_4(dp->ip6f_ident));
46-
ND_PRINT("%u|%zu)",
47-
GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
48-
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
49-
(bp - bp2) - sizeof(struct ip6_frag));
46+
ND_PRINT("%u|", GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK);
47+
if ((bp - bp2) + sizeof(struct ip6_frag) >
48+
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen))
49+
ND_PRINT("[length < 0] (invalid))");
50+
else
51+
ND_PRINT("%zu)",
52+
sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
53+
(bp - bp2) - sizeof(struct ip6_frag));
5054

5155
/* it is meaningless to decode non-first fragment */
5256
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
@@ -386,6 +386,7 @@ ipv6_invalid_length_2 ipv6_invalid_length_2.pcap ipv6_invalid_length_2.out -v
386386
ipv6_jumbogram_invalid_length ipv6_jumbogram_invalid_length.pcap ipv6_jumbogram_invalid_length.out -v
387387
ipv6_39_byte_header ipv6_39_byte_header.pcap ipv6_39_byte_header.out -v
388388
ipv6_missing_jumbo_payload_option ipv6_missing_jumbo_payload_option.pcap ipv6_missing_jumbo_payload_option.out
389+
ipv6_frag6_negative_len ipv6_frag6_negative_len.pcap ipv6_frag6_negative_len.out -v
389390

390391
# Loopback/CTP test case
391392
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)