]> The Tcpdump Group git mirrors - tcpdump/blobdiff - util-print.c
Revert partially the commit 21b1273
[tcpdump] / util-print.c
index 8806b47599c0c2723cbbbcfaead54ce262074cda..e22e535e8d2b2d62c9ead781614180d9f0301567 100644 (file)
@@ -473,21 +473,20 @@ void nd_print_invalid(netdissect_options *ndo)
  */
 
 int
-print_unknown_data(netdissect_options *ndo, const u_char *cp,const char *ident,int len)
+print_unknown_data(netdissect_options *ndo, const u_char *cp,
+                   const char *ident, u_int len)
 {
-       if (len < 0) {
-          ND_PRINT("%sDissector error: print_unknown_data called with negative length",
-                   ident);
-               return(0);
-       }
-       if (ndo->ndo_snapend - cp < len)
-               len = ndo->ndo_snapend - cp;
-       if (len < 0) {
-          ND_PRINT("%sDissector error: print_unknown_data called with pointer past end of packet",
+       u_int len_to_print;
+
+       len_to_print = len;
+       if (!ND_TTEST_LEN(cp, 0)) {
+               ND_PRINT("%sDissector error: print_unknown_data called with pointer past end of packet",
                    ident);
                return(0);
        }
-        hex_print(ndo, ident,cp,len);
+       if (ND_BYTES_AVAILABLE_AFTER(cp) < len_to_print)
+               len_to_print = ND_BYTES_AVAILABLE_AFTER(cp);
+       hex_print(ndo, ident, cp, len_to_print);
        return(1); /* everything is ok */
 }
 
@@ -779,7 +778,6 @@ print_txt_line(netdissect_options *ndo, const char *prefix,
 
        startidx = idx;
        while (idx < len) {
-               ND_TCHECK_1(pptr + idx);
                c = GET_U_1(pptr + idx);
                if (c == '\n') {
                        /*
@@ -796,7 +794,6 @@ print_txt_line(netdissect_options *ndo, const char *prefix,
                                /* not in this packet */
                                return (0);
                        }
-                       ND_TCHECK_1(pptr + idx + 1);
                        if (GET_U_1(pptr + idx + 1) == '\n') {
                                /*
                                 * CR-LF; end of line.
@@ -829,7 +826,6 @@ print_txt_line(netdissect_options *ndo, const char *prefix,
         * All printable ASCII, but no line ending after that point
         * in the buffer; treat this as if it were truncated.
         */
-trunc:
        linelen = idx - startidx;
        ND_PRINT("%s%.*s", prefix, (int)linelen, pptr + startidx);
        nd_print_trunc(ndo);