summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorhannes <hannes>2006-02-08 01:38:16 +0000
committerhannes <hannes>2006-02-08 01:38:16 +0000
commitddb7009f906c69c5f7bddbd21c735a117f9a1e49 (patch)
tree4f1272bf3b55110c84d7e0b671aaee74cb5d9658 /util.c
parent6b3e20d2916f8f799c342c4228585f2fe44fe242 (diff)
downloadtcpdump-ddb7009f906c69c5f7bddbd21c735a117f9a1e49.tar.gz
add a maxlen boundary check to safeputs, print unprintable chars as hex in safeputchar
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 6 insertions, 4 deletions
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);
}