X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/791d0e8bb742d7d860125a596aa21eba3d296aab..5d7eda16f08dc9dbf3ccad5ed1c6cbd4a46ef4a8:/util.c diff --git a/util.c b/util.c index 97d35272..4e04b0a9 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.94 2004-06-15 23:05:06 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.99 2005-05-06 08:26:45 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -45,7 +45,7 @@ static const char rcsid[] _U_ = #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. */ @@ -104,6 +104,40 @@ fn_printn(register const u_char *s, register u_int n, 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 : ret; +} + /* * Print the timestamp */ @@ -208,6 +242,8 @@ relts_print(int secs) int print_unknown_data(const u_char *cp,const char *ident,int len) { + if (snapend - cp < len) + len = snapend - cp; hex_print(ident,cp,len); return(1); /* everything is ok */ } @@ -219,10 +255,12 @@ const char * tok2strbuf(register const struct tok *lp, register const char *fmt, register int v, char *buf, size_t bufsize) { - while (lp->s != NULL) { - if (lp->v == v) - return (lp->s); - ++lp; + if (lp != NULL) { + while (lp->s != NULL) { + if (lp->v == v) + return (lp->s); + ++lp; + } } if (fmt == NULL) fmt = "#%d"; @@ -260,7 +298,7 @@ bittok2str(register const struct tok *lp, register const char *fmt, register int rotbit; /* this is the bit we rotate through all bitpositions */ register int tokval; - while (lp->s != NULL) { + while (lp->s != NULL && lp != NULL) { tokval=lp->v; /* load our first value */ rotbit=1; while (rotbit != 0) {