aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-01-29 14:19:25 -0500
committerMichael Mann <mmann78@netscape.net>2017-01-30 00:05:39 +0000
commitc44c8f9e6c7b633eae3129c58aab991ddc8678ed (patch)
tree7c862670618cfaf30f1efcbb5aa2bbc461e1bc04 /epan
parentb3035df88796e0e9058b315791861b03b3b59af7 (diff)
Have format_text_chr use wmem allocated memory.
Change-Id: Idcea59f6fc84238f04d9ffc11a0088ef97beec0c Reviewed-on: https://code.wireshark.org/review/19844 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-mq-pcf.c14
-rw-r--r--epan/dissectors/packet-mq.c6
-rw-r--r--epan/dissectors/packet-sysdig-event.c2
-rw-r--r--epan/strutil.c32
-rw-r--r--epan/strutil.h5
5 files changed, 26 insertions, 33 deletions
diff --git a/epan/dissectors/packet-mq-pcf.c b/epan/dissectors/packet-mq-pcf.c
index 1886fbc591..e19f2e7143 100644
--- a/epan/dissectors/packet-mq-pcf.c
+++ b/epan/dissectors/packet-mq-pcf.c
@@ -270,7 +270,7 @@ void dissect_mqpcf_parm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mq_tree,
if (*sStr)
strip_trailing_blanks(sStr, uSLn);
if (*sStr)
- format_text_chr(sStr, strlen((const char *)sStr), '.');
+ sStr = (guint8*)format_text_chr(wmem_packet_scope(), sStr, strlen((const char *)sStr), '.');
tree = proto_tree_add_subtree_format(mq_tree, tvb, offset, uLen, ett_mqpcf_prm, NULL, "%s %s", strPrm, sStr);
@@ -343,7 +343,7 @@ void dissect_mqpcf_parm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mq_tree,
if (*sStr)
strip_trailing_blanks(sStr, uSLn);
if (*sStr)
- format_text_chr(sStr, strlen((const char *)sStr), '.');
+ sStr = (guint8*)format_text_chr(wmem_packet_scope(), sStr, strlen((const char *)sStr), '.');
proto_tree_add_string_format(tree, hf_mq_pcf_stringlist, tvb, offset, uSLn, (const char *)sStr,
"%s[%*d]: %s", hfinfo->name, uDigit, u2+1, sStr);
@@ -372,8 +372,8 @@ void dissect_mqpcf_parm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mq_tree,
uSLn = tvb_get_guint32(tvb, offset + uLenF, bLittleEndian);
if (uSLn)
{
- guint8 *sStrA = (guint8 *)format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 4, uSLn, ENC_ASCII) , uSLn, '.');
- guint8 *sStrE = (guint8 *)format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 4, uSLn, ENC_EBCDIC), uSLn, '.');
+ guint8 *sStrA = (guint8 *)format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 4, uSLn, ENC_ASCII) , uSLn, '.');
+ guint8 *sStrE = (guint8 *)format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 4, uSLn, ENC_EBCDIC), uSLn, '.');
if (uSLn > 35)
{
tree = proto_tree_add_subtree_format(mq_tree, tvb, offset, uLen, ett_mqpcf_prm, NULL,
@@ -428,7 +428,7 @@ void dissect_mqpcf_parm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mq_tree,
uOpe = tvb_get_guint32(tvb, offset + uLenF, bLittleEndian);
uCCS = tvb_get_guint32(tvb, offset + uLenF + 4, bLittleEndian);
uSLn = tvb_get_guint32(tvb, offset + uLenF + 8, bLittleEndian);
- sStr = (guint8 *)format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 12, uSLn, (uCCS != 500) ? ENC_ASCII : ENC_EBCDIC), uSLn, '.');
+ sStr = (guint8 *)format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 12, uSLn, (uCCS != 500) ? ENC_ASCII : ENC_EBCDIC), uSLn, '.');
strip_trailing_blanks(sStr, uSLn);
tree = proto_tree_add_subtree_format(mq_tree, tvb, offset, uLen, ett_mqpcf_prm, NULL, "%s %s %s",
@@ -451,8 +451,8 @@ void dissect_mqpcf_parm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mq_tree,
uSLn = tvb_get_guint32(tvb, offset + uLenF + 4, bLittleEndian);
if (uSLn)
{
- guint8 *sStrA = (guint8 *)format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 8, uSLn, ENC_ASCII), uSLn, '.');
- guint8 *sStrE = (guint8 *)format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 8, uSLn, ENC_EBCDIC), uSLn, '.');
+ guint8 *sStrA = (guint8 *)format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 8, uSLn, ENC_ASCII), uSLn, '.');
+ guint8 *sStrE = (guint8 *)format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset + uLenF + 8, uSLn, ENC_EBCDIC), uSLn, '.');
tree = proto_tree_add_subtree_format(mq_tree, tvb, offset, uLen, ett_mqpcf_prm, NULL, "%s %s A(%s) E(%s)",
strPrm, val_to_str(uOpe, GET_VALSV(FilterOP), " Unknown (0x%02x)")+7, sStrA, sStrE);
}
diff --git a/epan/dissectors/packet-mq.c b/epan/dissectors/packet-mq.c
index 06ac0a3bf3..b4a841bc48 100644
--- a/epan/dissectors/packet-mq.c
+++ b/epan/dissectors/packet-mq.c
@@ -2844,12 +2844,12 @@ static void dissect_mq_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
iApp = tvb_get_guint32(tvb, offset + 48 + 28, iCod);
- sApplicationName = format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 48, 28, iEnc), 28, '.');
+ sApplicationName = format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 48, 28, iEnc), 28, '.');
if (strip_trailing_blanks((guint8 *)sApplicationName, 28) > 0)
{
col_append_fstr(pinfo->cinfo, COL_INFO, " App=%s", sApplicationName);
}
- sQMgr = format_text_chr(tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 48, iEnc), 48, '.');
+ sQMgr = format_text_chr(wmem_packet_scope(), tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 48, iEnc), 48, '.');
if (strip_trailing_blanks((guint8 *)sQMgr, 48) > 0)
{
col_append_fstr(pinfo->cinfo, COL_INFO, " QM=%s", sQMgr);
@@ -3740,7 +3740,7 @@ static void dissect_mq_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (*sStr)
strip_trailing_blanks(sStr, iLenStr);
if (*sStr)
- format_text_chr(sStr, strlen((const char *)sStr), '.');
+ sStr = (guint8*)format_text_chr(wmem_packet_scope(), sStr, strlen((const char *)sStr), '.');
rfh_tree = proto_tree_add_subtree_format(mq_tree, tvb, iPos, iLenStr+4, ett_mq_rfh_ValueName, NULL, "NameValue: %s", sStr);
diff --git a/epan/dissectors/packet-sysdig-event.c b/epan/dissectors/packet-sysdig-event.c
index 90ea1a2b34..93e27b4949 100644
--- a/epan/dissectors/packet-sysdig-event.c
+++ b/epan/dissectors/packet-sysdig-event.c
@@ -1839,7 +1839,7 @@ static inline const gchar *format_param_str(tvbuff_t *tvb, int offset, int len)
if (len < 2) {
return param_str;
}
- return format_text_chr(param_str, len - 1, ' '); /* Leave terminating NULLs alone. */
+ return format_text_chr(wmem_packet_scope(), param_str, len - 1, ' '); /* Leave terminating NULLs alone. */
}
/* Code to actually dissect the packets */
diff --git a/epan/strutil.c b/epan/strutil.c
index 715001e6b1..ad560699d6 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -359,24 +359,14 @@ format_text_wsp(const guchar *string, size_t len)
* which will be replaced by a space, and return a pointer to it.
*/
gchar *
-format_text_chr(const guchar *string, const size_t len, const guchar chr)
+format_text_chr(wmem_allocator_t* allocator, const guchar *string, const size_t len, const guchar chr)
{
- static gchar *fmtbuf[3];
- static int fmtbuf_len[3];
- static int idx;
+ gchar *fmtbuf = (gchar*)wmem_alloc(allocator, INITIAL_FMTBUF_SIZE);
+ int fmtbuf_len = INITIAL_FMTBUF_SIZE;
int column;
const guchar *stringend = string + len;
guchar c;
- idx = (idx + 1) % 3;
-
- /*
- * Allocate the buffer if it's not already allocated.
- */
- if (fmtbuf[idx] == NULL) {
- fmtbuf[idx] = (gchar *)g_malloc(INITIAL_FMTBUF_SIZE);
- fmtbuf_len[idx] = INITIAL_FMTBUF_SIZE;
- }
column = 0;
while (string < stringend)
{
@@ -384,7 +374,7 @@ format_text_chr(const guchar *string, const size_t len, const guchar chr)
* Is there enough room for this character,
* and also enough room for a terminating '\0'?
*/
- if (column+1 >= fmtbuf_len[idx])
+ if (column+1 >= fmtbuf_len)
{
/*
* Double the buffer's size if it's not big enough.
@@ -392,29 +382,29 @@ format_text_chr(const guchar *string, const size_t len, const guchar chr)
* adds at least another 128 bytes, which is more than enough
* for one more character plus a terminating '\0'.
*/
- fmtbuf_len[idx] = fmtbuf_len[idx] * 2;
- fmtbuf[idx] = (gchar *)g_realloc(fmtbuf[idx], fmtbuf_len[idx]);
+ fmtbuf_len *= 2;
+ fmtbuf = (gchar *)wmem_realloc(allocator, fmtbuf, fmtbuf_len);
}
c = *string++;
if (g_ascii_isprint(c))
{
- fmtbuf[idx][column] = c;
+ fmtbuf[column] = c;
column++;
}
else if (g_ascii_isspace(c))
{
- fmtbuf[idx][column] = ' ';
+ fmtbuf[column] = ' ';
column++;
}
else
{
- fmtbuf[idx][column] = chr;
+ fmtbuf[column] = chr;
column++;
}
}
- fmtbuf[idx][column] = '\0';
- return fmtbuf[idx];
+ fmtbuf[column] = '\0';
+ return fmtbuf;
}
static gboolean
diff --git a/epan/strutil.h b/epan/strutil.h
index 62c1dac564..3e76cbbf2f 100644
--- a/epan/strutil.h
+++ b/epan/strutil.h
@@ -25,6 +25,8 @@
#include "ws_symbol_export.h"
+#include <epan/wmem/wmem.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -88,6 +90,7 @@ gchar* format_text_wsp(const guchar *line, size_t len);
* (space, tab, carriage return, new line, vertical tab, or formfeed)
* which will be replaced by a space, and return a pointer to it.
*
+ * @param allocator The wmem scope
* @param string A pointer to the input string
* @param len The length of the input string
* @param chr The character to use to replace non-printable characters
@@ -95,7 +98,7 @@ gchar* format_text_wsp(const guchar *line, size_t len);
*
*/
WS_DLL_PUBLIC
-gchar* format_text_chr(const guchar *string, const size_t len, const guchar chr);
+gchar* format_text_chr(wmem_allocator_t* allocator, const guchar *string, const size_t len, const guchar chr);
/** Turn a string of hex digits with optional separators (defined by