]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
OSPF: Use %zu to print sizeof values
[tcpdump] / print-ip.c
index 0f09b04e8ebe1744446ef800ef65d818c8eb96af..7cec64041dd84ff99a46a98fe355db1c2dfa58f3 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "netdissect-stdinc.h"
 
-#include <string.h>
-
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -53,7 +51,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 +60,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 +69,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 +276,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:
@@ -496,7 +500,6 @@ ip_print(netdissect_options *ndo,
 
 trunc:
        nd_print_trunc(ndo);
-       return;
 }
 
 void