tcpdump mailing list archives
Re: tok2str() patch
From: "Gisle Vanem" <giva () bgnett no>
Date: Wed, 28 Apr 2004 12:49:45 +0200
I've had problem replying to the list, so this is just a test. BTW. tok2str() is still vulnerable. ----- Original Message ----- From: "Gisle Vanem" <giva () bgnett no> To: "tcpdump-workers" <tcpdump-workers () tcpdump org> Sent: Wednesday, March 24, 2004 9:26 PM Subject: [tcpdump-workers] tok2str() patch
tok2str() is in several files used multiple times in the same
printf() statement. This doesn't work if all values 'v' are unknown.
I suggest we allow for max 4 buffer to be returned in a round-robin
fashion.
--- tcpdump-2004.03.24/util.c Mon Dec 29 12:07:17 2003
+++ util.c Wed Mar 24 20:22:23 2004
@@ -212,7 +212,9 @@
tok2str(register const struct tok *lp, register const char *fmt,
register int v)
{
- static char buf[128];
+ static char buf[4][128];
+ static int idx = 0;
+ char *ret;
while (lp->s != NULL) {
if (lp->v == v)
@@ -221,8 +223,10 @@
}
if (fmt == NULL)
fmt = "#%d";
- (void)snprintf(buf, sizeof(buf), fmt, v);
- return (buf);
+ ret = buf[idx];
+ (void)snprintf(ret, sizeof(buf[0]), fmt, v);
+ idx = (idx+1) & 3;
+ return (const char*) ret;
}
--gv
- This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
Current thread:
- Re: tok2str() patch Gisle Vanem (Apr 28)
- Re: tok2str() patch Michael Richardson (Apr 29)
