summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-01-29 18:51:00 -0500
committerMichael Mann <mmann78@netscape.net>2017-01-30 02:25:45 +0000
commitf789c91a5ebbbefba51aa3da983fe836ebc860d6 (patch)
treece4a066bc1d1e8fe4a3bfc1f49e171d8aeda33d2 /epan
parent9365fd3d3a4cdac07d70bd77f7a42f3260b33b5e (diff)
downloadwireshark-f789c91a5ebbbefba51aa3da983fe836ebc860d6.tar.gz
Have format_text_wsp use wmem allocated memory.
format_text_wsp is fed into by tvb_format_text_wsp and tvb_format_stringzpad_wsp so those functions need to add a wmem allocated parameter as well. Most of the changes came from tvb_format_text_wsp and tvb_format_stringzpad_wsp being changed more so than format_text_wsp. Change-Id: I52214ca107016f0e96371a9a8430aa89336f91d7 Reviewed-on: https://code.wireshark.org/review/19851 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-adb_service.c6
-rw-r--r--epan/dissectors/packet-at.c2
-rw-r--r--epan/dissectors/packet-bthfp.c2
-rw-r--r--epan/dissectors/packet-bthsp.c2
-rw-r--r--epan/dissectors/packet-gsmtap_log.c2
-rw-r--r--epan/dissectors/packet-imf.c2
-rw-r--r--epan/dissectors/packet-megaco.c2
-rw-r--r--epan/dissectors/packet-packetlogger.c2
-rw-r--r--epan/dissectors/packet-rpcap.c4
-rw-r--r--epan/dissectors/packet-sip.c2
-rw-r--r--epan/proto.c5
-rw-r--r--epan/strutil.c52
-rw-r--r--epan/strutil.h3
-rw-r--r--epan/tvbuff.c8
-rw-r--r--epan/tvbuff.h4
15 files changed, 46 insertions, 52 deletions
diff --git a/epan/dissectors/packet-adb_service.c b/epan/dissectors/packet-adb_service.c
index 7e60edd587..1e29019739 100644
--- a/epan/dissectors/packet-adb_service.c
+++ b/epan/dissectors/packet-adb_service.c
@@ -538,11 +538,11 @@ dissect_adb_service(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
} else if (g_str_has_prefix(service, "shell:")) {
if (adb_service_data->direction == P2P_DIR_SENT) {
proto_tree_add_item(main_tree, hf_stdin, tvb, offset, -1, ENC_NA | ENC_ASCII);
- col_append_fstr(pinfo->cinfo, COL_INFO, " Stdin=<%s>", tvb_format_text_wsp(tvb, offset, tvb_captured_length_remaining(tvb, offset)));
+ col_append_fstr(pinfo->cinfo, COL_INFO, " Stdin=<%s>", tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
} else {
proto_tree_add_item(main_tree, hf_stdout, tvb, offset, -1, ENC_NA | ENC_ASCII);
- col_append_fstr(pinfo->cinfo, COL_INFO, " Stdout=<%s>", tvb_format_text_wsp(tvb, offset, tvb_captured_length_remaining(tvb, offset)));
+ col_append_fstr(pinfo->cinfo, COL_INFO, " Stdout=<%s>", tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
}
offset = tvb_captured_length(tvb);
} else if (g_str_has_prefix(service, "jdwp:")) {
@@ -560,7 +560,7 @@ dissect_adb_service(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
g_str_has_prefix(service, "usb:")) {
if (tvb_reported_length_remaining(tvb, offset)) {
proto_tree_add_item(main_tree, hf_result, tvb, offset, -1, ENC_NA | ENC_ASCII);
- col_append_fstr(pinfo->cinfo, COL_INFO, " Result=<%s>", tvb_format_text_wsp(tvb, offset, tvb_captured_length_remaining(tvb, offset)));
+ col_append_fstr(pinfo->cinfo, COL_INFO, " Result=<%s>", tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
offset = tvb_captured_length(tvb);
}
diff --git a/epan/dissectors/packet-at.c b/epan/dissectors/packet-at.c
index a03bc00b30..2ab569fe0e 100644
--- a/epan/dissectors/packet-at.c
+++ b/epan/dissectors/packet-at.c
@@ -57,7 +57,7 @@ static int dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
proto_tree *at_tree;
gchar *string;
- string = tvb_format_text_wsp(tvb, 0, tvb_captured_length(tvb));
+ string = tvb_format_text_wsp(wmem_packet_scope(), tvb, 0, tvb_captured_length(tvb));
col_append_sep_str(pinfo->cinfo, COL_PROTOCOL, "/", "AT");
col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "AT Command: %s", string);
diff --git a/epan/dissectors/packet-bthfp.c b/epan/dissectors/packet-bthfp.c
index ea267792af..285fa47fac 100644
--- a/epan/dissectors/packet-bthfp.c
+++ b/epan/dissectors/packet-bthfp.c
@@ -2231,7 +2231,7 @@ dissect_bthfp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
}
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s",
- tvb_format_text_wsp(tvb, offset, tvb_captured_length_remaining(tvb, offset)));
+ tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
pitem = proto_tree_add_item(main_tree, hf_fragmented, tvb, 0, 0, ENC_NA);
PROTO_ITEM_SET_GENERATED(pitem);
proto_tree_add_item(main_tree, hf_fragment, tvb, offset,
diff --git a/epan/dissectors/packet-bthsp.c b/epan/dissectors/packet-bthsp.c
index 19e8484a6f..c3872c4deb 100644
--- a/epan/dissectors/packet-bthsp.c
+++ b/epan/dissectors/packet-bthsp.c
@@ -999,7 +999,7 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
}
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s",
- tvb_format_text_wsp(tvb, offset, tvb_captured_length_remaining(tvb, offset)));
+ tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
pitem = proto_tree_add_item(main_tree, hf_fragmented, tvb, 0, 0, ENC_NA);
PROTO_ITEM_SET_GENERATED(pitem);
proto_tree_add_item(main_tree, hf_fragment, tvb, offset,
diff --git a/epan/dissectors/packet-gsmtap_log.c b/epan/dissectors/packet-gsmtap_log.c
index 9bb6e49d53..3f851cac32 100644
--- a/epan/dissectors/packet-gsmtap_log.c
+++ b/epan/dissectors/packet-gsmtap_log.c
@@ -87,7 +87,7 @@ dissect_gsmtap_log(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * d
log_str_len = tvb_captured_length_remaining(tvb, offset);
proto_tree_add_item(log_tree, hf_log_string, tvb, offset, log_str_len, ENC_ASCII|ENC_NA);
- log_str = tvb_format_stringzpad_wsp(tvb, offset, log_str_len);
+ log_str = tvb_format_stringzpad_wsp(wmem_packet_scope(), tvb, offset, log_str_len);
col_append_str(pinfo->cinfo, COL_INFO, log_str);
proto_item_append_text(ti, " %s(%u): %s/%d: %s:%u %s",
diff --git a/epan/dissectors/packet-imf.c b/epan/dissectors/packet-imf.c
index f4b518ea38..54e7c8e4c6 100644
--- a/epan/dissectors/packet-imf.c
+++ b/epan/dissectors/packet-imf.c
@@ -909,7 +909,7 @@ dissect_imf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
*/
proto_tree_add_format_wsp_text(text_tree, tvb, start_offset, end_offset - start_offset);
col_append_sep_str(pinfo->cinfo, COL_INFO, ", ",
- tvb_format_text_wsp(tvb, start_offset, end_offset - start_offset));
+ tvb_format_text_wsp(wmem_packet_scope(), tvb, start_offset, end_offset - start_offset));
/*
* Step to the next line.
diff --git a/epan/dissectors/packet-megaco.c b/epan/dissectors/packet-megaco.c
index c58e96cb37..07194a53ba 100644
--- a/epan/dissectors/packet-megaco.c
+++ b/epan/dissectors/packet-megaco.c
@@ -2700,7 +2700,7 @@ dissect_megaco_topologydescriptor(tvbuff_t *tvb, proto_tree *megaco_tree_command
tokenlen = (tvb_RBRKT+1) - tvb_previous_offset;
proto_tree_add_string(megaco_tree_command_line, hf_megaco_topology_descriptor, tvb,
tvb_previous_offset, tokenlen,
- tvb_format_text_wsp(tvb, tvb_previous_offset,
+ tvb_format_text_wsp(wmem_packet_scope(), tvb, tvb_previous_offset,
tokenlen));
}
diff --git a/epan/dissectors/packet-packetlogger.c b/epan/dissectors/packet-packetlogger.c
index 6c0da73f1a..8eb6466d9c 100644
--- a/epan/dissectors/packet-packetlogger.c
+++ b/epan/dissectors/packet-packetlogger.c
@@ -148,7 +148,7 @@ static int dissect_packetlogger(tvbuff_t *tvb, packet_info *pinfo,
case PKT_NOTE:
case PKT_NEW_CONTROLLER:
proto_tree_add_item (packetlogger_tree, hf_info, next_tvb, 0, len, ENC_ASCII|ENC_NA);
- col_add_fstr (pinfo->cinfo, COL_INFO, "%s", tvb_format_stringzpad_wsp (next_tvb, 0, len));
+ col_add_fstr (pinfo->cinfo, COL_INFO, "%s", tvb_format_stringzpad_wsp (wmem_packet_scope(), next_tvb, 0, len));
break;
default:
call_data_dissector(next_tvb, pinfo, tree);
diff --git a/epan/dissectors/packet-rpcap.c b/epan/dissectors/packet-rpcap.c
index eb0ebb03be..740e94cc02 100644
--- a/epan/dissectors/packet-rpcap.c
+++ b/epan/dissectors/packet-rpcap.c
@@ -382,11 +382,11 @@ dissect_rpcap_error (tvbuff_t *tvb, packet_info *pinfo,
return;
col_append_fstr (pinfo->cinfo, COL_INFO, ": %s",
- tvb_format_text_wsp (tvb, offset, len));
+ tvb_format_text_wsp (wmem_packet_scope(), tvb, offset, len));
ti = proto_tree_add_item (parent_tree, hf_error, tvb, offset, len, ENC_ASCII|ENC_NA);
expert_add_info_format(pinfo, ti, &ei_error,
- "Error: %s", tvb_format_text_wsp (tvb, offset, len));
+ "Error: %s", tvb_format_text_wsp (wmem_packet_scope(), tvb, offset, len));
}
diff --git a/epan/dissectors/packet-sip.c b/epan/dissectors/packet-sip.c
index a7c007f918..eca88dcb22 100644
--- a/epan/dissectors/packet-sip.c
+++ b/epan/dissectors/packet-sip.c
@@ -4696,7 +4696,7 @@ tvb_raw_text_add(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
linelen = next_offset - offset;
if (raw_tree) {
if (global_sip_raw_text_without_crlf)
- str = tvb_format_text_wsp(tvb, offset, linelen);
+ str = tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, linelen);
else
str = tvb_format_text(tvb, offset, linelen);
proto_tree_add_string_format(raw_tree, hf_sip_raw_line, tvb, offset, linelen,
diff --git a/epan/proto.c b/epan/proto.c
index d42ac90a7a..42c0227ba0 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1338,6 +1338,7 @@ proto_tree_add_format_wsp_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint
{
proto_item *pi;
header_field_info *hfinfo;
+ gchar* str;
CHECK_FOR_NULL_TREE(tree);
@@ -1347,7 +1348,9 @@ proto_tree_add_format_wsp_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint
TRY_TO_FAKE_THIS_REPR(pi);
- proto_item_set_text(pi, "%s", tvb_format_text_wsp(tvb, start, length));
+ str = tvb_format_text_wsp(NULL, tvb, start, length);
+ proto_item_set_text(pi, "%s", str);
+ wmem_free(NULL, str);
return pi;
}
diff --git a/epan/strutil.c b/epan/strutil.c
index ad560699d6..c4a65849a4 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -250,25 +250,15 @@ format_text(const guchar *string, size_t len)
* which will be replaced by a space, and return a pointer to it.
*/
gchar *
-format_text_wsp(const guchar *string, size_t len)
+format_text_wsp(wmem_allocator_t* allocator, const guchar *string, size_t len)
{
- 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;
int i;
- 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) {
/*
@@ -276,80 +266,80 @@ format_text_wsp(const guchar *string, size_t len)
* a backslash plus 3 octal digits (which is the most it can
* expand to), and also enough room for a terminating '\0'?
*/
- if (column+3+1 >= fmtbuf_len[idx]) {
+ if (column+3+1 >= fmtbuf_len) {
/*
* Double the buffer's size if it's not big enough.
* The size of the buffer starts at 128, so doubling its size
* 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] = '\\';
+ fmtbuf[column] = '\\';
column++;
switch (c) {
case '\a':
- fmtbuf[idx][column] = 'a';
+ fmtbuf[column] = 'a';
column++;
break;
case '\b':
- fmtbuf[idx][column] = 'b'; /* BS */
+ fmtbuf[column] = 'b'; /* BS */
column++;
break;
case '\f':
- fmtbuf[idx][column] = 'f'; /* FF */
+ fmtbuf[column] = 'f'; /* FF */
column++;
break;
case '\n':
- fmtbuf[idx][column] = 'n'; /* NL */
+ fmtbuf[column] = 'n'; /* NL */
column++;
break;
case '\r':
- fmtbuf[idx][column] = 'r'; /* CR */
+ fmtbuf[column] = 'r'; /* CR */
column++;
break;
case '\t':
- fmtbuf[idx][column] = 't'; /* tab */
+ fmtbuf[column] = 't'; /* tab */
column++;
break;
case '\v':
- fmtbuf[idx][column] = 'v';
+ fmtbuf[column] = 'v';
column++;
break;
default:
i = (c>>6)&03;
- fmtbuf[idx][column] = i + '0';
+ fmtbuf[column] = i + '0';
column++;
i = (c>>3)&07;
- fmtbuf[idx][column] = i + '0';
+ fmtbuf[column] = i + '0';
column++;
i = (c>>0)&07;
- fmtbuf[idx][column] = i + '0';
+ fmtbuf[column] = i + '0';
column++;
break;
}
}
}
- fmtbuf[idx][column] = '\0';
- return fmtbuf[idx];
+ fmtbuf[column] = '\0';
+ return fmtbuf;
}
/*
diff --git a/epan/strutil.h b/epan/strutil.h
index 3e76cbbf2f..8cba9112fb 100644
--- a/epan/strutil.h
+++ b/epan/strutil.h
@@ -76,13 +76,14 @@ gchar* format_text(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 line A pointer to the input string
* @param len The length of the input string
* @return A pointer to the formatted string
*
*/
WS_DLL_PUBLIC
-gchar* format_text_wsp(const guchar *line, size_t len);
+gchar* format_text_wsp(wmem_allocator_t* allocator, const guchar *line, size_t len);
/**
* Given a string, generate a string from it that shows non-printable
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 2d5408ab23..2d95e173f8 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -2190,7 +2190,7 @@ tvb_format_text(tvbuff_t *tvb, const gint offset, const gint size)
* Format the data in the tvb from offset for length ...
*/
gchar *
-tvb_format_text_wsp(tvbuff_t *tvb, const gint offset, const gint size)
+tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint offset, const gint size)
{
const guint8 *ptr;
gint len;
@@ -2198,7 +2198,7 @@ tvb_format_text_wsp(tvbuff_t *tvb, const gint offset, const gint size)
len = (size > 0) ? size : 0;
ptr = ensure_contiguous(tvb, offset, size);
- return format_text_wsp(ptr, len);
+ return format_text_wsp(allocator, ptr, len);
}
/*
@@ -2225,7 +2225,7 @@ tvb_format_stringzpad(tvbuff_t *tvb, const gint offset, const gint size)
* the null padding characters as "\000".
*/
gchar *
-tvb_format_stringzpad_wsp(tvbuff_t *tvb, const gint offset, const gint size)
+tvb_format_stringzpad_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint offset, const gint size)
{
const guint8 *ptr, *p;
gint len;
@@ -2236,7 +2236,7 @@ tvb_format_stringzpad_wsp(tvbuff_t *tvb, const gint offset, const gint size)
ptr = ensure_contiguous(tvb, offset, size);
for (p = ptr, stringlen = 0; stringlen < len && *p != '\0'; p++, stringlen++)
;
- return format_text_wsp(ptr, stringlen);
+ return format_text_wsp(allocator, ptr, stringlen);
}
/* Unicode REPLACEMENT CHARACTER */
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index 3b009555d4..3023655bff 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -545,7 +545,7 @@ WS_DLL_PUBLIC gchar *tvb_format_text(tvbuff_t *tvb, const gint offset,
* Like "tvb_format_text()", but for 'wsp'; don't show
* the characters as C-style escapes.
*/
-WS_DLL_PUBLIC gchar *tvb_format_text_wsp(tvbuff_t *tvb, const gint offset,
+WS_DLL_PUBLIC gchar *tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint offset,
const gint size);
/**
@@ -559,7 +559,7 @@ extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, const gint offset,
* Like "tvb_format_text_wsp()", but for null-padded strings; don't show
* the null padding characters as "\000".
*/
-extern gchar *tvb_format_stringzpad_wsp(tvbuff_t *tvb, const gint offset,
+extern gchar *tvb_format_stringzpad_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint offset,
const gint size);
/**