]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add an "fn_printzp()" routine for printing null-padded strings (strings
authorguy <guy>
Fri, 6 May 2005 07:57:17 +0000 (07:57 +0000)
committerguy <guy>
Fri, 6 May 2005 07:57:17 +0000 (07:57 +0000)
with a maximum length, where a string shorter than that length is padded
with NULs), as "fn_print()" won't handle the maximum length *and* the
snapshot length and "fn_printn()" won't stop on a null string.  Use it
where appropriate.

Always pass "snapend" to "fn_print()" and "fn_printn()" if they're
passed a pointer into the packet data; only pass NULL if they're being
handed a pointer into a buffer that's not part of the packet data.

Always check the return value of "fn_print()", "fn_printn()", and
"fn_printzp()" if they're passed "snapend", and do the appropriate
string termination and "packet truncated" indication if they return 1.

interface.h
print-hsrp.c
print-ipx.c
print-nfs.c
print-ntp.c
print-ospf.c
print-snmp.c
print-vrrp.c
util.c

index ca8701fc01402b9885b7b9308e7bc1c1e9b279f6..f85e44124a09938601e314c70edb6efa16870d42 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.244.2.5 2005-05-03 20:39:25 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.244.2.6 2005-05-06 07:57:17 guy Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
  */
 
 #ifndef tcpdump_interface_h
@@ -137,6 +137,7 @@ extern void relts_print(int);
 
 extern int fn_print(const u_char *, const u_char *);
 extern int fn_printn(const u_char *, u_int, const u_char *);
 
 extern int fn_print(const u_char *, const u_char *);
 extern int fn_printn(const u_char *, u_int, const u_char *);
+extern int fn_printzp(const u_char *, u_int, const u_char *);
 extern int mask2plen(u_int32_t);
 extern const char *tok2strary_internal(const char **, int, const char *, int);
 #define        tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
 extern int mask2plen(u_int32_t);
 extern const char *tok2strary_internal(const char **, int, const char *, int);
 #define        tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
index fe49538e45dfc46d1897f06e65c8459496bba69f..21ec05404e112fc3bcb82a02fe7d24bc3f4dce48 100644 (file)
@@ -31,7 +31,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-hsrp.c,v 1.9 2003-11-16 09:36:22 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-hsrp.c,v 1.9.2.1 2005-05-06 07:57:17 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -127,7 +127,11 @@ hsrp_print(register const u_int8_t *bp, register u_int len)
                relts_print(hp->hsrp_holdtime);
                printf(" priority=%d", hp->hsrp_priority);
                printf(" auth=\"");
                relts_print(hp->hsrp_holdtime);
                printf(" priority=%d", hp->hsrp_priority);
                printf(" auth=\"");
-               fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), NULL);
+               if (fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata),
+                   snapend)) {
+                       printf("\"");
+                       goto trunc;
+               }
                printf("\"");
        }
        return;
                printf("\"");
        }
        return;
index b5f6de6d2b574892fb2f10b571f283d88eb41312..77fbcb6775284d6e44282a91e0d0855537555bcf 100644 (file)
@@ -24,7 +24,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.40 2004-05-26 19:57:57 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.40.2.1 2005-05-06 07:57:18 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -161,7 +161,10 @@ ipx_sap_print(const u_short *ipx, u_int length)
        for (i = 0; i < 8 && length > 0; i++) {
            TCHECK2(ipx[25], 10);
            (void)printf(" %s '", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0]))));
        for (i = 0; i < 8 && length > 0; i++) {
            TCHECK2(ipx[25], 10);
            (void)printf(" %s '", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0]))));
-           fn_print((u_char *)&ipx[1], (u_char *)&ipx[1] + 48);
+           if (fn_printzp((u_char *)&ipx[1], 48, snapend)) {
+               printf("'");
+               goto trunc;
+           }
            printf("' addr %s",
                ipxaddr_string(EXTRACT_32BITS(&ipx[25]), (u_char *)&ipx[27]));
            ipx += 32;
            printf("' addr %s",
                ipxaddr_string(EXTRACT_32BITS(&ipx[25]), (u_char *)&ipx[27]));
            ipx += 32;
index d74f43ffbce48c53f0c6c0cbf80f167831f47ee1..7502823e51883f3260de43e9394cb9cd9e14a30b 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.106.2.1 2005-04-20 21:52:31 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.106.2.2 2005-05-06 07:57:18 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -388,9 +388,11 @@ parsefn(register const u_int32_t *dp)
        cp = (u_char *)dp;
        /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
        dp += ((len + 3) & ~3) / sizeof(*dp);
        cp = (u_char *)dp;
        /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
        dp += ((len + 3) & ~3) / sizeof(*dp);
-       /* XXX seems like we should be checking the length */
        putchar('"');
        putchar('"');
-       (void) fn_printn(cp, len, NULL);
+       if (fn_printn(cp, len, snapend)) {
+               putchar('"');
+               goto trunc;
+       }
        putchar('"');
 
        return (dp);
        putchar('"');
 
        return (dp);
index f9b65b2596abdfdab4156714c0742bd3cd65d5df..b408e0877e460874f330e1d34752e212fd939eee 100644 (file)
@@ -25,7 +25,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.41 2004-01-28 14:54:50 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.41.2.1 2005-05-06 07:57:18 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -133,7 +133,8 @@ ntp_print(register const u_char *cp, u_int length)
                break;
 
        case PRIM_REF:
                break;
 
        case PRIM_REF:
-               fn_printn((u_char *)&(bp->refid), 4, NULL);
+               if (fn_printn((u_char *)&(bp->refid), 4, snapend))
+                       goto trunc;
                break;
 
        case INFO_QUERY:
                break;
 
        case INFO_QUERY:
index f9cff38bfdb1f7faff0a912b267ca0d418856073..60cb6eb99a1e5663def6c1ff8ebae4e52fcb5fab 100644 (file)
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.56.2.1 2005-04-20 21:55:32 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.56.2.2 2005-05-06 07:57:19 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -932,8 +932,11 @@ ospf_print(register const u_char *bp, register u_int length,
                        break;
 
                case OSPF_AUTH_SIMPLE:
                        break;
 
                case OSPF_AUTH_SIMPLE:
-                       (void)fn_printn(op->ospf_authdata,
-                           sizeof(op->ospf_authdata), NULL);
+                       if (fn_printn(op->ospf_authdata,
+                           sizeof(op->ospf_authdata), snapend)) {
+                               printf("\"");
+                               goto trunc;
+                       }
                        printf("\"");
                        break;
 
                        printf("\"");
                        break;
 
index 387a9d5aaa7ebc2e4bec17d8ef097a4f6a914de9..15e440f5d91a6a6ba925aa4e1ef73513a2011a04 100644 (file)
@@ -58,7 +58,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.62.2.1 2005-04-18 00:08:02 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.62.2.2 2005-05-06 07:57:19 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -786,7 +786,10 @@ asn1_print(struct be *elem)
                p = elem->data.str;
                if (printable) {
                        putchar('"');
                p = elem->data.str;
                if (printable) {
                        putchar('"');
-                       (void)fn_print(p, p + asnlen);
+                       if (fn_printn(p, asnlen, snapend)) {
+                               putchar('"');
+                               goto trunc;
+                       }
                        putchar('"');
                } else
                        for (i = asnlen; i-- > 0; p++) {
                        putchar('"');
                } else
                        for (i = asnlen; i-- > 0; p++) {
index 12fbe7b30764db286971fcc5753d6b2d92f13ffa..12e47716e0c9ae4cdaab6cf6d5fd9a1438df7e1a 100644 (file)
@@ -25,7 +25,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.9 2003-11-16 09:36:41 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.9.2.1 2005-05-06 07:57:20 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -128,7 +128,10 @@ vrrp_print(register const u_char *bp, register u_int len, int ttl)
                if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */
                        TCHECK(bp[7]);
                        printf(" auth \"");
                if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */
                        TCHECK(bp[7]);
                        printf(" auth \"");
-                       fn_printn(bp, 8, NULL);
+                       if (fn_printn(bp, 8, snapend)) {
+                               printf("\"");
+                               goto trunc;
+                       }
                        printf("\"");
                }
        }
                        printf("\"");
                }
        }
diff --git a/util.c b/util.c
index 27b36f49b4027303bf29643d209f28e473825840..f64430517523bfd951540c9e4b289e24be82a67c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.95.2.2 2005-04-26 03:44:36 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.95.2.3 2005-05-06 07:57:20 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -45,7 +45,7 @@ static const char rcsid[] _U_ =
 #include "interface.h"
 
 /*
 #include "interface.h"
 
 /*
- * Print out a filename (or other ascii string).
+ * Print out a null-terminated filename (or other ascii string).
  * If ep is NULL, assume no truncation check is needed.
  * Return true if truncated.
  */
  * If ep is NULL, assume no truncation check is needed.
  * Return true if truncated.
  */
@@ -104,6 +104,40 @@ fn_printn(register const u_char *s, register u_int n,
        return (n == 0) ? 0 : 1;
 }
 
        return (n == 0) ? 0 : 1;
 }
 
+/*
+ * Print out a null-padded filename (or other ascii string).
+ * If ep is NULL, assume no truncation check is needed.
+ * Return true if truncated.
+ */
+int
+fn_printzp(register const u_char *s, register u_int n,
+         register const u_char *ep)
+{
+       register int ret;
+       register u_char c;
+
+       ret = 1;                        /* assume truncated */
+       while (n > 0 && (ep == NULL || s < ep)) {
+               n--;
+               c = *s++;
+               if (c == '\0') {
+                       ret = 0;
+                       break;
+               }
+               if (!isascii(c)) {
+                       c = toascii(c);
+                       putchar('M');
+                       putchar('-');
+               }
+               if (!isprint(c)) {
+                       c ^= 0x40;      /* DEL to ?, others to alpha */
+                       putchar('^');
+               }
+               putchar(c);
+       }
+       return (n == 0) ? 0 : 1;
+}
+
 /*
  * Print the timestamp
  */
 /*
  * Print the timestamp
  */