aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/dissectors/packet-ber.c2
-rw-r--r--epan/dissectors/packet-bootp.c3
-rw-r--r--epan/dissectors/packet-clnp.c18
-rw-r--r--epan/dissectors/packet-icmpv6.c3
-rw-r--r--epan/dissectors/packet-isakmp.c3
-rw-r--r--epan/dissectors/packet-ldap.c2
-rw-r--r--epan/dissectors/packet-mip6.c2
-rw-r--r--epan/dissectors/packet-ntp.c20
-rw-r--r--epan/dissectors/packet-ospf.c7
-rw-r--r--epan/dissectors/packet-pim.c2
-rw-r--r--epan/dissectors/packet-ppp.c8
-rw-r--r--epan/dissectors/packet-ptp.c4
-rw-r--r--epan/dissectors/packet-pvfs2.c2
-rw-r--r--epan/dissectors/packet-radius.c29
-rw-r--r--epan/dissectors/packet-radius.h2
-rw-r--r--epan/dissectors/packet-smb-sidsnooping.c3
-rw-r--r--epan/dissectors/packet-tcp.c6
-rw-r--r--epan/dissectors/packet-tr.c2
-rw-r--r--epan/dissectors/packet-windows-common.c5
19 files changed, 64 insertions, 59 deletions
diff --git a/epan/dissectors/packet-ber.c b/epan/dissectors/packet-ber.c
index dd809eed3b..801b57abf9 100644
--- a/epan/dissectors/packet-ber.c
+++ b/epan/dissectors/packet-ber.c
@@ -2084,7 +2084,7 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, packet_info *pinfo, proto_tre
tmpstr=tvb_get_ptr(tvb, offset, len);
- snprintf(str, 31, "%.4s-%.2s-%.2s %.2s:%.2s:%.2s (%.1s)",
+ g_snprintf(str, 32, "%.4s-%.2s-%.2s %.2s:%.2s:%.2s (%.1s)",
tmpstr, tmpstr+4, tmpstr+6, tmpstr+8,
tmpstr+10, tmpstr+12, tmpstr+14);
str[31]=0; /* just in case ... */
diff --git a/epan/dissectors/packet-bootp.c b/epan/dissectors/packet-bootp.c
index a875e1ed25..32e9e6b2bc 100644
--- a/epan/dissectors/packet-bootp.c
+++ b/epan/dissectors/packet-bootp.c
@@ -2293,9 +2293,6 @@ dissect_docsis_cm_cap(proto_tree *v_tree, tvbuff_t *tvb, int voff, int len)
return;
} else {
/* Value(s) */
- /*strptr+=g_snprintf(strptr, TLV_STR_LEN-(strptr-tlv_str), "Length: %d, Value%s: ", tlv_len,
- plurality(tlv_len, "", "s") );*/
-
ti = proto_tree_add_text(v_tree, tvb, off,
(tlv_len * 2) + 4,
"0x%s: %s = ",
diff --git a/epan/dissectors/packet-clnp.c b/epan/dissectors/packet-clnp.c
index 1e759199fc..8c99b34a9e 100644
--- a/epan/dissectors/packet-clnp.c
+++ b/epan/dissectors/packet-clnp.c
@@ -418,8 +418,9 @@ static gboolean is_all_printable(const guchar *stringtocheck, int length)
static gchar *print_tsap(const guchar *tsap, int length)
{
- gchar *cur, *tmp;
+ gchar *cur;
gboolean allprintable;
+ size_t index = 0, returned_length;
cur=ep_alloc(MAX_TSAP_LEN * 2 + 3);
cur[0] = '\0';
@@ -427,14 +428,17 @@ static gchar *print_tsap(const guchar *tsap, int length)
g_snprintf(cur, MAX_TSAP_LEN * 2 + 3, "<unsupported TSAP length>");
else {
allprintable = is_all_printable(tsap,length);
- tmp=cur;
if (!allprintable)
- tmp+=g_snprintf(tmp, (MAX_TSAP_LEN * 2 + 3)-(tmp-cur), "0x");
+ returned_length = g_snprintf(cur, MAX_TSAP_LEN * 2 + 3, "0x");
+ index += MIN(returned_length, MAX_TSAP_LEN * 2 + 3 - 1);
while (length != 0) {
- if (allprintable)
- tmp+=g_snprintf(tmp, (MAX_TSAP_LEN * 2 + 3)-(tmp-cur), "%c", *tsap ++);
- else
- tmp+=g_snprintf(tmp, (MAX_TSAP_LEN * 2 + 3)-(tmp-cur), "%02x", *tsap ++);
+ if (allprintable) {
+ returned_length = g_snprintf(&cur[index], MAX_TSAP_LEN * 2 + 3 - index, "%c", *tsap ++);
+ index += MIN(returned_length, MAX_TSAP_LEN * 2 + 3 - index - 1 );
+ } else {
+ returned_length = g_snprintf(&cur[index], MAX_TSAP_LEN * 2 + 3 - index, "%02x", *tsap ++);
+ index += MIN(returned_length, MAX_TSAP_LEN * 2 + 3 - index - 1);
+ }
length --;
}
}
diff --git a/epan/dissectors/packet-icmpv6.c b/epan/dissectors/packet-icmpv6.c
index 67c1a95703..74c5cd1458 100644
--- a/epan/dissectors/packet-icmpv6.c
+++ b/epan/dissectors/packet-icmpv6.c
@@ -682,8 +682,7 @@ bitrange0(guint32 v, int s, char *buf, int buflen)
l = g_snprintf(p, ep - p, ",%d-%d", s + off,
s + off + i - 1);
}
- if (l == -1 || l > ep - p) {
- buf[0] = '\0';
+ if (l == -1 || l >= ep - p) {
return NULL;
}
v >>= i; off += i;
diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c
index 9edb7ac4bb..fedf590ee5 100644
--- a/epan/dissectors/packet-isakmp.c
+++ b/epan/dissectors/packet-isakmp.c
@@ -2060,7 +2060,6 @@ situation2str(guint32 type)
ret = g_snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep);
if (ret == -1 || ret >= SIT_MSG_NUM-n) {
/* Truncated. */
- msg[SIT_MSG_NUM-1] = '\0';
return msg;
}
n += ret;
@@ -2074,7 +2073,6 @@ situation2str(guint32 type)
ret = g_snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep);
if (ret == -1 || ret >= SIT_MSG_NUM-n) {
/* Truncated. */
- msg[SIT_MSG_NUM-1] = '\0';
return msg;
}
n += ret;
@@ -2088,7 +2086,6 @@ situation2str(guint32 type)
ret = g_snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep);
if (ret == -1 || ret >= SIT_MSG_NUM-n) {
/* Truncated. */
- msg[SIT_MSG_NUM-1] = '\0';
return msg;
}
n += ret;
diff --git a/epan/dissectors/packet-ldap.c b/epan/dissectors/packet-ldap.c
index 57e53e1f47..719655c95a 100644
--- a/epan/dissectors/packet-ldap.c
+++ b/epan/dissectors/packet-ldap.c
@@ -661,7 +661,7 @@ static int parse_filter_strings(ASN1_SCK *a, char **filter, guint *filter_length
*filter = g_realloc(*filter, *filter_length);
filterp = *filter + strlen(*filter);
- filterp += g_snprintf(filterp, (*filter_length)-(filterp-*filter), "(%s%s%s)", string, operation, string2);
+ g_snprintf(filterp, (*filter_length)-(filterp-*filter), "(%s%s%s)", string, operation, string2);
g_free(string);
g_free(string2);
diff --git a/epan/dissectors/packet-mip6.c b/epan/dissectors/packet-mip6.c
index c189e7ddb8..1846b1fa83 100644
--- a/epan/dissectors/packet-mip6.c
+++ b/epan/dissectors/packet-mip6.c
@@ -681,7 +681,7 @@ dissect_mipv6_options(tvbuff_t *tvb, int offset, guint length,
optp = NULL; /* indicate that we don't know this option */
len_type = VARIABLE_LENGTH;
optlen = 0;
- snprintf(name_str, sizeof name_str, "Unknown (0x%02x)", opt);
+ g_snprintf(name_str, sizeof name_str, "Unknown (0x%02x)", opt);
name = name_str;
dissect = NULL;
} else {
diff --git a/epan/dissectors/packet-ntp.c b/epan/dissectors/packet-ntp.c
index 320af8b5d1..1f95aa55c9 100644
--- a/epan/dissectors/packet-ntp.c
+++ b/epan/dissectors/packet-ntp.c
@@ -549,24 +549,22 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
*/
refid = tvb_get_ptr(tvb, 12, 4);
if (stratum <= 1) {
- int buffpos=0;
buff=ep_alloc(NTP_TS_SIZE);
- buffpos += g_snprintf (buff, NTP_TS_SIZE,
- "Unindentified reference source '%.4s'",
- refid);
+ g_snprintf (buff, NTP_TS_SIZE, "Unindentified reference source '%.4s'",
+ refid);
for (i = 0; primary_sources[i].id; i++) {
- if (memcmp (refid, primary_sources[i].id,
- 4) == 0) {
- buffpos += g_snprintf(buff, NTP_TS_SIZE-buffpos, "%s", primary_sources[i].data);
+ if (memcmp (refid, primary_sources[i].id, 4) == 0) {
+ g_snprintf(buff, NTP_TS_SIZE, "%s",
+ primary_sources[i].data);
break;
}
}
} else {
- int buffpos=0;
- buff=ep_alloc(NTP_TS_SIZE);
+ int buffpos;
+ buff = ep_alloc(NTP_TS_SIZE);
refid_addr = tvb_get_ipv4(tvb, 12);
- buffpos += g_snprintf(buff, NTP_TS_SIZE, get_hostname (refid_addr));
- if (buffpos>=(NTP_TS_SIZE-1)){
+ buffpos = g_snprintf(buff, NTP_TS_SIZE, get_hostname (refid_addr));
+ if (buffpos >= NTP_TS_SIZE) {
buff[NTP_TS_SIZE-4]='.';
buff[NTP_TS_SIZE-3]='.';
buff[NTP_TS_SIZE-2]='.';
diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c
index 988fc6e351..95261f1946 100644
--- a/epan/dissectors/packet-ospf.c
+++ b/epan/dissectors/packet-ospf.c
@@ -823,9 +823,11 @@ dissect_ospf_bitfield (proto_tree *parent_tree, tvbuff_t *tvb, int offset,
proto_tree *tree = NULL;
guint32 flags;
char *str;
- gint length, pos, i;
+ size_t length, pos;
+ gint i;
header_field_info *hfinfo;
int hfindex, index;
+ size_t returned_length;
hfindex = ospf_filter[bfinfo->hfindex];
hfinfo = proto_registrar_get_nth(hfindex);
@@ -860,9 +862,10 @@ dissect_ospf_bitfield (proto_tree *parent_tree, tvbuff_t *tvb, int offset,
index = ospf_filter[bfinfo->index[i]];
hfinfo = proto_registrar_get_nth(index);
if (flags & hfinfo->bitmask) {
- pos += g_snprintf(str+pos, MAX_OPTIONS_LEN-pos, "%s%s",
+ returned_length = g_snprintf(&str[pos], MAX_OPTIONS_LEN-pos, "%s%s",
pos ? ", " : "",
hfinfo->name);
+ pos += MIN(returned_length, MAX_OPTIONS_LEN-pos);
}
proto_tree_add_boolean(tree, index, tvb, offset, length, flags);
}
diff --git a/epan/dissectors/packet-pim.c b/epan/dissectors/packet-pim.c
index 23f52f6b04..aee93f57ea 100644
--- a/epan/dissectors/packet-pim.c
+++ b/epan/dissectors/packet-pim.c
@@ -78,7 +78,7 @@ dissect_pimv1_addr(tvbuff_t *tvb, int offset) {
flags_masklen & 0x0040 ? "R" : "");
} else
buf[0] = '\0';
- g_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s/%u",
+ g_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s/%u",
ip_to_str(tvb_get_ptr(tvb, offset + 2, 4)), flags_masklen & 0x3f);
return buf;
diff --git a/epan/dissectors/packet-ppp.c b/epan/dissectors/packet-ppp.c
index 6bd3313ba3..9624dc8f35 100644
--- a/epan/dissectors/packet-ppp.c
+++ b/epan/dissectors/packet-ppp.c
@@ -1654,7 +1654,7 @@ dissect_lcp_async_map_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
"DLE", "DC1 (XON)", "DC2", "DC3 (XOFF)", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
};
- char *mapp;
+ size_t returned_length, str_index;
int i;
/*
@@ -1673,10 +1673,12 @@ dissect_lcp_async_map_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
/*
* Show the names of the control characters being mapped.
*/
- mapp = mapstr;
+ str_index = 0;
for (i = 0; i < 32; i++) {
if (map & (1 << i)) {
- mapp+=g_snprintf(mapp, MAX_MAPSTR_LEN-(mapp-mapstr), "%s%s", (mapp==mapstr)?"":", ", ctrlchars[i]);
+ returned_length = g_snprintf(&mapstr[str_index], MAX_MAPSTR_LEN-str_index,
+ "%s%s", str_index?"":", ", ctrlchars[i]);
+ str_index += MIN(returned_length, MAX_MAPSTR_LEN-str_index);
}
}
}
diff --git a/epan/dissectors/packet-ptp.c b/epan/dissectors/packet-ptp.c
index a5a9aad20b..f6a20f0e9c 100644
--- a/epan/dissectors/packet-ptp.c
+++ b/epan/dissectors/packet-ptp.c
@@ -43,10 +43,6 @@
#include <glib.h>
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
#include <epan/packet.h>
diff --git a/epan/dissectors/packet-pvfs2.c b/epan/dissectors/packet-pvfs2.c
index 5f858c4f21..269fdb0037 100644
--- a/epan/dissectors/packet-pvfs2.c
+++ b/epan/dissectors/packet-pvfs2.c
@@ -875,7 +875,7 @@ dissect_pvfs_opaque_data(tvbuff_t *tvb, int offset,
/* alloc maximum data area */
string_buffer_print = (char*) ep_alloc(string_buffer_size);
/* copy over the data */
- g_snprintf(string_buffer_print, string_buffer_size - 1,
+ g_snprintf(string_buffer_print, string_buffer_size,
"%s<TRUNCATED>", formatted);
/* append <TRUNCATED> */
/* This way, we get the TRUNCATED even
diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c
index 08c4faaac0..45eeb502f6 100644
--- a/epan/dissectors/packet-radius.c
+++ b/epan/dissectors/packet-radius.c
@@ -285,14 +285,16 @@ radius_decrypt_avp(gchar *dest,int dest_len,tvbuff_t *tvb,int offset,int length)
md5_state_t md_ctx;
md5_byte_t digest[16];
int i;
- int totlen;
+ size_t totlen, returned_length;
const guint8 *pd;
guchar c;
+ DISSECTOR_ASSERT(dest_len > 2); /* \"\"\0 */
dest[0] = '"';
dest[1] = '\0';
totlen = 1;
-
+ dest_len -= 1; /* Need to add trailing \" */
+
md5_init(&md_ctx);
md5_append(&md_ctx,(const guint8*)shared_secret,strlen(shared_secret));
md5_append(&md_ctx,authenticator, AUTHENTICATOR_LENGTH);
@@ -301,24 +303,29 @@ radius_decrypt_avp(gchar *dest,int dest_len,tvbuff_t *tvb,int offset,int length)
pd = tvb_get_ptr(tvb,offset,length);
for( i = 0 ; i < AUTHENTICATOR_LENGTH && i < length ; i++ ) {
c = pd[i] ^ digest[i];
- if ( isprint(c)) {
- dest[totlen] = c;
- totlen++;
+ if ( isprint(c) ) {
+ returned_length = g_snprintf(&dest[totlen], dest_len-totlen,
+ "%c",c);
+ totlen += MIN(returned_length, dest_len-totlen-1);
} else {
- totlen += g_snprintf(dest+totlen, dest_len-totlen, "\\%03o",c);
+ returned_length = g_snprintf(&dest[totlen], dest_len-totlen,
+ "\\%03o",c);
+ totlen += MIN(returned_length, dest_len-totlen-1);
}
}
while(i<length) {
if ( isprint(pd[i]) ) {
- dest[totlen] = (gchar)pd[i];
- totlen++;
+ returned_length = g_snprintf(&dest[totlen], dest_len-totlen,
+ "%c", pd[i]);
+ totlen += MIN(returned_length, dest_len-totlen-1);
} else {
- totlen += g_snprintf(dest+totlen, dest_len-totlen, "\\%03o", pd[i]);
+ returned_length = g_snprintf(&dest[totlen], dest_len-totlen,
+ "\\%03o", pd[i]);
+ totlen += MIN(returned_length, dest_len-totlen-1);
}
i++;
}
- dest[totlen]='"';
- dest[totlen+1] = '\0';
+ g_snprintf(&dest[totlen], dest_len+1-totlen, "%c", '"');
}
diff --git a/epan/dissectors/packet-radius.h b/epan/dissectors/packet-radius.h
index 7c1f195305..01d3dc13d8 100644
--- a/epan/dissectors/packet-radius.h
+++ b/epan/dissectors/packet-radius.h
@@ -24,7 +24,7 @@
*/
typedef struct _radius_vendor_info_t {
- gchar *name;
+ const gchar *name;
guint code;
GHashTable* attrs_by_id;
gint ett;
diff --git a/epan/dissectors/packet-smb-sidsnooping.c b/epan/dissectors/packet-smb-sidsnooping.c
index 19dd526126..edaf793972 100644
--- a/epan/dissectors/packet-smb-sidsnooping.c
+++ b/epan/dissectors/packet-smb-sidsnooping.c
@@ -209,8 +209,7 @@ samr_query_dispinfo(void *dummy _U_, packet_info *pinfo, epan_dissect_t *edt, co
fi_name=gp_names->pdata[num_rids-1];
strncpy(sid_name, sid, len);
sid_name[len++]='-';
- len+=g_snprintf(sid_name+len, 256-len, "%d",fi_rid->value.value.integer);
- sid_name[len]=0;
+ g_snprintf(sid_name+len, 256-len, "%d",fi_rid->value.value.integer);
add_sid_name_mapping(sid_name, fi_name->value.value.string);
}
return 1;
diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c
index bbddc7b80d..c97a0151b2 100644
--- a/epan/dissectors/packet-tcp.c
+++ b/epan/dissectors/packet-tcp.c
@@ -2678,7 +2678,8 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
int offset = 0;
gchar *flags = "<None>";
const gchar *fstr[] = {"FIN", "SYN", "RST", "PSH", "ACK", "URG", "ECN", "CWR" };
- gint fpos = 0, i;
+ size_t fpos = 0, returned_length;
+ gint i;
guint bpos;
guint optlen;
guint32 nxtseq = 0;
@@ -2806,9 +2807,10 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
for (i = 0; i < 8; i++) {
bpos = 1 << i;
if (tcph->th_flags & bpos) {
- fpos+=g_snprintf(flags+fpos, MAX_FLAGS_LEN-fpos, "%s%s",
+ returned_length = g_snprintf(&flags[fpos], MAX_FLAGS_LEN-fpos, "%s%s",
fpos?", ":"",
fstr[i]);
+ fpos += MIN(returned_length, MAX_FLAGS_LEN-fpos);
}
}
}
diff --git a/epan/dissectors/packet-tr.c b/epan/dissectors/packet-tr.c
index dc7d632f4f..4e0f03b3af 100644
--- a/epan/dissectors/packet-tr.c
+++ b/epan/dissectors/packet-tr.c
@@ -613,12 +613,14 @@ add_ring_bridge_pairs(int rcf_len, tvbuff_t *tvb, proto_tree *tree)
if (j==1) {
segment = tvb_get_ntohs(tvb, RIF_OFFSET) >> 4;
size = g_snprintf(buffer, MAX_BUF_LEN, "%03X",segment);
+ size = MIN(size, MAX_BUF_LEN - 1);
proto_tree_add_uint_hidden(tree, hf_tr_rif_ring, tvb, TR_MIN_HEADER_LEN + 2, 2, segment);
buff_offset += size;
}
segment = tvb_get_ntohs(tvb, RIF_OFFSET + 1 + j) >> 4;
brdgnmb = tvb_get_guint8(tvb, RIF_OFFSET + j) & 0x0f;
size = g_snprintf(buffer+buff_offset, MAX_BUF_LEN-buff_offset, "-%01X-%03X",brdgnmb,segment);
+ size = MIN(size, MAX_BUF_LEN-buff_offset-1);
proto_tree_add_uint_hidden(tree, hf_tr_rif_ring, tvb, TR_MIN_HEADER_LEN + 3 + j, 2, segment);
proto_tree_add_uint_hidden(tree, hf_tr_rif_bridge, tvb, TR_MIN_HEADER_LEN + 2 + j, 1, brdgnmb);
buff_offset += size;
diff --git a/epan/dissectors/packet-windows-common.c b/epan/dissectors/packet-windows-common.c
index 11b8ef24b9..832c52756c 100644
--- a/epan/dissectors/packet-windows-common.c
+++ b/epan/dissectors/packet-windows-common.c
@@ -1302,10 +1302,9 @@ dissect_nt_sid(tvbuff_t *tvb, int offset, proto_tree *parent_tree,
* assume that non le byte encodings will be "uncommon"?
*/
- DISSECTOR_ASSERT(str_index <= MAX_STR_LEN);
returned_length = g_snprintf(&str[str_index], MAX_STR_LEN-str_index,
(i>0 ? "-%u" : "%u"), tvb_get_letohl(tvb, offset));
- str_index += MIN(returned_length, (MAX_STR_LEN-str_index));
+ str_index += MIN(returned_length, MAX_STR_LEN-str_index);
offset+=4;
}
@@ -1838,7 +1837,7 @@ dissect_nt_v2_ace(tvbuff_t *tvb, int offset, packet_info *pinfo,
static int
dissect_nt_acl(tvbuff_t *tvb, int offset, packet_info *pinfo,
- proto_tree *parent_tree, guint8 *drep, char *name,
+ proto_tree *parent_tree, guint8 *drep, const char *name,
struct access_mask_info *ami)
{
proto_item *item = NULL;