From: hannes Date: Wed, 8 Feb 2006 01:38:16 +0000 (+0000) Subject: add a maxlen boundary check to safeputs, print unprintable chars as hex in safeputchar X-Git-Tag: tcpdump-4.0.0~266 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/ddb7009f906c69c5f7bddbd21c735a117f9a1e49 add a maxlen boundary check to safeputs, print unprintable chars as hex in safeputchar --- diff --git a/interface.h b/interface.h index deee3b97..ad9c4955 100644 --- a/interface.h +++ b/interface.h @@ -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 *); diff --git a/netdissect.h b/netdissect.h index dfc03d3c..1f1c1bbe 100644 --- a/netdissect.h +++ b/netdissect.h @@ -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 bee808c2..cb4f2aaa 100644 --- 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); }