]> The Tcpdump Group git mirrors - tcpdump/commitdiff
add a maxlen boundary check to safeputs, print unprintable chars as hex in safeputchar
authorhannes <hannes>
Wed, 8 Feb 2006 01:38:16 +0000 (01:38 +0000)
committerhannes <hannes>
Wed, 8 Feb 2006 01:38:16 +0000 (01:38 +0000)
interface.h
netdissect.h
util.c

index deee3b970ca147dd7a37805d2fb86bcebe439028..ad9c4955dfcc51eb922ca64f2b80ea67a4e60e7e 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.264 2005-12-13 13:44:29 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.265 2006-02-08 01:38:17 hannes Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -152,7 +152,7 @@ extern char *read_infile(char *);
 extern char *copy_argv(char **);
 
 extern void safeputchar(int);
-extern void safeputs(const char *);
+extern void safeputs(const char *, int);
 
 extern const char *isonsap_string(const u_char *, register u_int);
 extern const char *protoid_string(const u_char *);
index dfc03d3cae62b628cc76e840339dcd63e9a1ddde..1f1c1bbe092e7e132d13d36a401b5dda9af6dc92 100644 (file)
@@ -21,7 +21,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.20 2005-10-20 07:43:51 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/netdissect.h,v 1.21 2006-02-08 01:38:17 hannes Exp $ (LBL)
  */
 
 #ifndef netdissect_h
@@ -234,7 +234,7 @@ extern char *copy_argv(netdissect_options *, char **);
 #endif
 
 extern void safeputchar(int);
-extern void safeputs(const char *);
+extern void safeputs(const char *, int);
 
 #if 0
 extern const char *isonsap_string(netdissect_options *, const u_char *);
diff --git a/util.c b/util.c
index bee808c26b329bfed05b29d9968513ff9a4d95f2..cb4f2aaa768ce16a5fd07261f14c6d0ee4b1e9cd 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.105 2006-01-22 19:06:37 gianluca Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.106 2006-02-08 01:38:16 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -526,10 +526,12 @@ read_infile(char *fname)
 }
 
 void
-safeputs(const char *s)
+safeputs(const char *s, int maxlen)
 {
-       while (*s) {
+    int idx = 0;
+       while (*s && idx < maxlen) {
                safeputchar(*s);
+                idx++;
                s++;
        }
 }
@@ -543,5 +545,5 @@ safeputchar(int c)
        if (ch < 0x80 && isprint(ch))
                printf("%c", ch);
        else
-               printf("\\%03o", ch);
+               printf("\\0x%02x ", ch);
 }