aboutsummaryrefslogtreecommitdiffstats
path: root/packet-ieee80211.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-09-25 02:21:15 +0000
committerGuy Harris <guy@alum.mit.edu>2001-09-25 02:21:15 +0000
commit12db23546de313dd28f797c080134334bb28ba92 (patch)
tree22650d606435fcfb54ae7bfa117115c91c3cbce0 /packet-ieee80211.c
parent7ee55bfd6b96e4a0f6c6e8919ab616961380b94b (diff)
downloadwireshark-12db23546de313dd28f797c080134334bb28ba92.tar.gz
wireshark-12db23546de313dd28f797c080134334bb28ba92.tar.bz2
wireshark-12db23546de313dd28f797c080134334bb28ba92.zip
If "snprintf()" can't print all the data because there's not enough
room, it might return -1 in some versions of glibc; check for that, and quit if that happens. It might also return the number of characters that would've been printed had there been enough room; this means that a loop that does n += snprintf (buf + n, BUF_LENGTH - n, ...); may end up making "n" bigger than BUF_LENGTH, and "snprintf()" might not sanely handle being passed a negative length, so if "n" isn't less than the total length of the string buffer, don't add stuff to it. svn path=/trunk/; revision=3952
Diffstat (limited to 'packet-ieee80211.c')
-rw-r--r--packet-ieee80211.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/packet-ieee80211.c b/packet-ieee80211.c
index 5f5ee1015c..64b6d3b379 100644
--- a/packet-ieee80211.c
+++ b/packet-ieee80211.c
@@ -3,7 +3,7 @@
* Copyright 2000, Axis Communications AB
* Inquiries/bugreports should be sent to Johan.Jorgensen@axis.com
*
- * $Id: packet-ieee80211.c,v 1.39 2001/09/25 00:34:24 guy Exp $
+ * $Id: packet-ieee80211.c,v 1.40 2001/09/25 02:21:15 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -597,7 +597,7 @@ add_tagged_field (proto_tree * tree, tvbuff_t * tvb, int offset)
const guint8 *tag_data_ptr;
guint32 tag_no, tag_len;
unsigned int i;
- int n;
+ int n, ret;
char out_buff[SHORT_STR];
@@ -667,13 +667,20 @@ add_tagged_field (proto_tree * tree, tvbuff_t * tvb, int offset)
strcpy (out_buff, "Supported rates: ");
n = strlen (out_buff);
- for (i = 0; i < tag_len; i++)
+ for (i = 0; i < tag_len && n < SHORT_STR; i++)
{
- n += snprintf (out_buff + n, SHORT_STR - n, "%2.1f%s ",
+ ret = snprintf (out_buff + n, SHORT_STR - n, "%2.1f%s ",
(tag_data_ptr[i] & 0x7F) * 0.5,
(tag_data_ptr[i] & 0x80) ? "(B)" : "");
+ if (ret == -1) {
+ /* Some versions of snprintf return -1 if they'd truncate
+ the output. */
+ break;
+ }
+ n += ret;
}
- snprintf (out_buff + n, SHORT_STR - n, "[Mbit/sec]");
+ if (n < SHORT_STR)
+ snprintf (out_buff + n, SHORT_STR - n, "[Mbit/sec]");
proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
tag_len, out_buff);