]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-domain.c
Add some additional bounds checking.
[tcpdump] / print-domain.c
index ff16d73707daf6302928a7e0386f811ce543095b..0e152e8c9499ee49b6047de2c67440f8e498713b 100644 (file)
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#ifndef lint
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.89 2004-03-23 19:03:03 fenner Exp $ (LBL)";
+#endif
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #include "addrtoname.h"
 #include "extract.h"                    /* must come after interface.h */
 
-#ifndef lint
-static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.87 2003-11-15 00:39:19 guy Exp $ (LBL)";
-#endif
 static const char *ns_ops[] = {
        "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7",
        " op8", " updataA", " updateD", " updateDA",
@@ -89,7 +89,6 @@ static const u_char *
 blabel_print(const u_char *cp)
 {
        int bitlen, slen, b;
-       int truncated = 0;
        const u_char *bitp, *lim;
        char tc;
 
@@ -98,27 +97,28 @@ blabel_print(const u_char *cp)
        if ((bitlen = *cp) == 0)
                bitlen = 256;
        slen = (bitlen + 3) / 4;
-       if ((lim = cp + 1 + slen) > snapend) {
-               truncated = 1;
-               lim = snapend;
-       }
+       lim = cp + 1 + slen;
 
        /* print the bit string as a hex string */
        printf("\\[x");
-       for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++)
+       for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
+               TCHECK(*bitp);
                printf("%02x", *bitp);
-       if (bitp == lim)
-               printf("...");
-       else if (b > 4) {
+       }
+       if (b > 4) {
+               TCHECK(*bitp);
                tc = *bitp++;
                printf("%02x", tc & (0xff << (8 - b)));
        } else if (b > 0) {
+               TCHECK(*bitp);
                tc = *bitp++;
                printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
        }
        printf("/%d]", bitlen);
-
-       return(truncated ? NULL : lim);
+       return lim;
+trunc:
+       printf(".../%d]", bitlen);
+       return NULL;
 }
 
 static int