]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-telnet.c
Remove EXTRACT_LE_8BITS() macro, use EXTRACT_8BITS() macro
[tcpdump] / print-telnet.c
index 2e32fce8af89e7320a96770b986dbeeec8200b99..10fad9fef7f6a5b8c9a045c8f59eeeccb0873829 100644 (file)
@@ -57,6 +57,8 @@
 
 #include "netdissect.h"
 
+static const char tstr[] = " [|telnet]";
+
 #define TELCMDS
 #define TELOPTS
 
@@ -435,10 +437,12 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
                /* IAC SB .... IAC SE */
                p = sp;
                while (length > (u_int)(p + 1 - sp)) {
+                       ND_TCHECK2(*p, 2);
                        if (p[0] == IAC && p[1] == SE)
                                break;
                        p++;
                }
+               ND_TCHECK(*p);
                if (*p != IAC)
                        goto pktend;
 
@@ -495,7 +499,7 @@ done:
        return sp - osp;
 
 trunc:
-       ND_PRINT((ndo, "[|telnet]"));
+       ND_PRINT((ndo, "%s", tstr));
 pktend:
        return -1;
 #undef FETCH
@@ -510,6 +514,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
 
        osp = sp;
 
+       ND_TCHECK(*sp);
        while (length > 0 && *sp == IAC) {
                /*
                 * Parse the Telnet command without printing it,
@@ -538,6 +543,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
 
                sp += l;
                length -= l;
+               ND_TCHECK(*sp);
        }
        if (!first) {
                if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag)
@@ -545,4 +551,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
                else
                        ND_PRINT((ndo, "]"));
        }
+       return;
+trunc:
+       ND_PRINT((ndo, "%s", tstr));
 }