summaryrefslogtreecommitdiff
path: root/print-ip.c
diff options
context:
space:
mode:
authorFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2020-09-20 16:43:19 +0200
committerFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2020-09-20 17:04:15 +0200
commitc98ea428912fa6b8518db17074662f8e885e72a0 (patch)
tree0e7ef5d62c10101e0c9cb29c81cbcd56e800e5ea /print-ip.c
parent38b7ae42d148b79c121dd7032c2319b28b19f145 (diff)
downloadtcpdump-c98ea428912fa6b8518db17074662f8e885e72a0.tar.gz
IP: Revert the commit 38b7ae42 and partially the commit aad6ac30
Add back a ND_TCHECK_4() call to print the IP source and destination addresses in truncation cases. Add a comment to explain why the ND_TCHECK_4 is needed.
Diffstat (limited to 'print-ip.c')
-rw-r--r--print-ip.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/print-ip.c b/print-ip.c
index 0f09b04e..187d36e6 100644
--- a/print-ip.c
+++ b/print-ip.c
@@ -53,7 +53,7 @@ static const struct tok ip_option_values[] = {
/*
* print the recorded route in an IP RR, LSRR or SSRR option.
*/
-static void
+static int
ip_printroute(netdissect_options *ndo,
const u_char *cp, u_int length)
{
@@ -62,7 +62,7 @@ ip_printroute(netdissect_options *ndo,
if (length < 3) {
ND_PRINT(" [bad length %u]", length);
- return;
+ return (0);
}
if ((length + 1) & 3)
ND_PRINT(" [bad length %u]", length);
@@ -71,10 +71,15 @@ ip_printroute(netdissect_options *ndo,
ND_PRINT(" [bad ptr %u]", GET_U_1(cp + 2));
for (len = 3; len < length; len += 4) {
+ ND_TCHECK_4(cp + len); /* Needed to print the IP addresses */
ND_PRINT(" %s", GET_IPADDR_STRING(cp + len));
if (ptr > len)
ND_PRINT(",");
}
+ return (0);
+
+trunc:
+ return (-1);
}
/*
@@ -273,7 +278,8 @@ ip_optprint(netdissect_options *ndo,
case IPOPT_RR: /* fall through */
case IPOPT_SSRR:
case IPOPT_LSRR:
- ip_printroute(ndo, cp, option_len);
+ if (ip_printroute(ndo, cp, option_len) == -1)
+ goto trunc;
break;
case IPOPT_RA: