From cdfab0d6e991df2fd3591ef896ba36937a8d4dfc Mon Sep 17 00:00:00 2001 From: Evan Huus Date: Fri, 27 Aug 2021 14:56:00 -0400 Subject: tvbuff: convert helper methods to pinfo->pool A few of them just needed scratch memory, so allocate and free it manually after doing any exception-raising checks. A few others were returning memory, and needed conversion to accept a wmem scope argument. --- epan/tvbuff.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'epan/tvbuff.c') diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 7a1d7956b9..c44bca3338 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1661,8 +1661,8 @@ GByteArray* tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length, const guint encoding, GByteArray *bytes, gint *endoff) { - const gchar *ptr = (gchar*) tvb_get_raw_string(wmem_packet_scope(), tvb, offset, length); - const gchar *begin = ptr; + gchar *ptr; + const gchar *begin; const gchar *end = NULL; GByteArray *retval = NULL; @@ -1670,6 +1670,9 @@ tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length, validate_single_byte_ascii_encoding(encoding); + ptr = (gchar*) tvb_get_raw_string(NULL, tvb, offset, length); + begin = ptr; + if (endoff) *endoff = 0; while (*begin == ' ') begin++; @@ -1684,6 +1687,8 @@ tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length, } } + wmem_free(NULL, ptr); + return retval; } @@ -1706,8 +1711,8 @@ nstime_t* tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length, const guint encoding, nstime_t *ns, gint *endoff) { - const gchar *begin = (gchar*) tvb_get_raw_string(wmem_packet_scope(), tvb, offset, length); - const gchar *ptr = begin; + gchar *begin; + const gchar *ptr; const gchar *end = NULL; struct tm tm; nstime_t* retval = NULL; @@ -1723,6 +1728,9 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length, DISSECTOR_ASSERT(ns); + begin = (gchar*) tvb_get_raw_string(NULL, tvb, offset, length); + ptr = begin; + memset(&tm, 0, sizeof(tm)); tm.tm_isdst = -1; ns->secs = 0; @@ -1916,6 +1924,8 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length, *endoff = (gint)(offset + (end - begin)); } + wmem_free(NULL, begin); + return retval; } @@ -2455,7 +2465,7 @@ tvb_memeql(tvbuff_t *tvb, const gint offset, const guint8 *str, size_t size) * wmem packet_scoped so call must be in that scope. */ gchar * -tvb_format_text(tvbuff_t *tvb, const gint offset, const gint size) +tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint size) { const guint8 *ptr; gint len; @@ -2463,7 +2473,7 @@ tvb_format_text(tvbuff_t *tvb, const gint offset, const gint size) len = (size > 0) ? size : 0; ptr = ensure_contiguous(tvb, offset, size); - return format_text(wmem_packet_scope(), ptr, len); + return format_text(scope, ptr, len); } /* @@ -2487,7 +2497,7 @@ tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint offse * so call must be in that scope. */ gchar * -tvb_format_stringzpad(tvbuff_t *tvb, const gint offset, const gint size) +tvb_format_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint size) { const guint8 *ptr, *p; gint len; @@ -2498,7 +2508,7 @@ tvb_format_stringzpad(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(wmem_packet_scope(), ptr, stringlen); + return format_text(scope, ptr, stringlen); } /* @@ -4305,21 +4315,21 @@ tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gi /* XXXX Fix me - needs odd indicator added */ const gchar * -tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first) +tvb_bcd_dig_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first) { if (!dgt) dgt = &Dgt0_9_bcd; - return tvb_get_bcd_string(wmem_packet_scope(), tvb, offset, len, dgt, skip_first, FALSE, FALSE); + return tvb_get_bcd_string(scope, tvb, offset, len, dgt, skip_first, FALSE, FALSE); } const gchar * -tvb_bcd_dig_to_wmem_packet_str_be(tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first) +tvb_bcd_dig_to_str_be(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first) { if (!dgt) dgt = &Dgt0_9_bcd; - return tvb_get_bcd_string(wmem_packet_scope(), tvb, offset, len, dgt, skip_first, FALSE, TRUE); + return tvb_get_bcd_string(scope, tvb, offset, len, dgt, skip_first, FALSE, TRUE); } /* -- cgit v1.2.3