The IPv6 header length field contains the payload length (excluding
the length of the IPv6 header itself). The IPv6 packet parser
calculates the length of the received packet correctly, but wrongly
uses the payload length (rather than the full packet length) when
checking for truncated packets.
Fix by calculating the packet length exactly once and using it for
both purposes.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
}
/* Truncate packet to specified length */
- len = ntohs ( iphdr->len );
+ len = ( sizeof ( *iphdr ) + ntohs ( iphdr->len ) );
if ( len > iob_len ( iobuf ) ) {
DBGC ( ipv6col ( &iphdr->src ), "IPv6 length too long at %zd "
"bytes (packet is %zd bytes)\n", len, iob_len ( iobuf ));
rc = -EINVAL_LEN;
goto err_other;
}
- iob_unput ( iobuf, ( iob_len ( iobuf ) - len - sizeof ( *iphdr ) ) );
+ iob_unput ( iobuf, ( iob_len ( iobuf ) - len ) );
hdrlen = sizeof ( *iphdr );
/* Print IPv6 header for debugging */