diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/crypt/airpdcap.c | 7 | ||||
-rw-r--r-- | epan/strutil.c | 35 | ||||
-rw-r--r-- | epan/strutil.h | 3 |
3 files changed, 20 insertions, 25 deletions
diff --git a/epan/crypt/airpdcap.c b/epan/crypt/airpdcap.c index f8fd0eec07..b1f5bdcc3e 100644 --- a/epan/crypt/airpdcap.c +++ b/epan/crypt/airpdcap.c @@ -2146,9 +2146,12 @@ get_key_string(decryption_key_t* dk) case AIRPDCAP_KEY_TYPE_WPA_PWD: if(dk->ssid == NULL) output_string = g_strdup(dk->key->str); - else + else { + gchar* ssid = format_uri(NULL, dk->ssid, ":"); output_string = g_strdup_printf("%s:%s", - dk->key->str, format_uri(dk->ssid, ":")); + dk->key->str, ssid); + wmem_free(NULL, ssid); + } break; case AIRPDCAP_KEY_TYPE_WPA_PMK: output_string = g_strdup(dk->key->str); diff --git a/epan/strutil.c b/epan/strutil.c index e32cfcaab9..ef9daaae7d 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -689,12 +689,11 @@ uri_str_to_bytes(const char *uri_str, GByteArray *bytes) * Given a GByteArray, generate a string from it that shows non-printable * characters as percent-style escapes, and return a pointer to it. */ -const gchar * -format_uri(const GByteArray *bytes, const gchar *reserved_chars) +gchar * +format_uri(wmem_allocator_t* allocator, const GByteArray *bytes, const gchar *reserved_chars) { - static gchar *fmtbuf[3]; - static guint fmtbuf_len[3]; - static guint idx; + gchar *fmtbuf = (gchar*)wmem_alloc(allocator, INITIAL_FMTBUF_SIZE); + guint fmtbuf_len = INITIAL_FMTBUF_SIZE; static const guchar *reserved_def = ":/?#[]@!$&'()*+,;= "; const guchar *reserved = reserved_def; guint8 c; @@ -704,32 +703,24 @@ format_uri(const GByteArray *bytes, const gchar *reserved_chars) if (! bytes) return ""; - idx = (idx + 1) % 3; if (reserved_chars) reserved = reserved_chars; - /* - * 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; - } for (column = 0; column < bytes->len; column++) { /* * Is there enough room for this character, if it expands to * a percent plus 2 hex digits (which is the most it can * expand to), and also enough room for a terminating '\0'? */ - if (column+2+1 >= fmtbuf_len[idx]) { + if (column+2+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 = bytes->data[column]; @@ -743,17 +734,17 @@ format_uri(const GByteArray *bytes, const gchar *reserved_chars) } if (!is_reserved) { - fmtbuf[idx][column] = c; + fmtbuf[column] = c; } else { - fmtbuf[idx][column] = '%'; + fmtbuf[column] = '%'; column++; - fmtbuf[idx][column] = hex[c >> 4]; + fmtbuf[column] = hex[c >> 4]; column++; - fmtbuf[idx][column] = hex[c & 0xF]; + fmtbuf[column] = hex[c & 0xF]; } } - fmtbuf[idx][column] = '\0'; - return fmtbuf[idx]; + fmtbuf[column] = '\0'; + return fmtbuf; } /** diff --git a/epan/strutil.h b/epan/strutil.h index d7a7560b32..6a0f1588d6 100644 --- a/epan/strutil.h +++ b/epan/strutil.h @@ -158,6 +158,7 @@ gboolean uri_str_to_bytes(const char *uri_str, GByteArray *bytes); /** Turn a byte array into an RFC 3986 percent-encoded string. * + * @param allocator The wmem scope * @param bytes The GByteArray that will receive the bytes. This * must be initialized by the caller. * @param reserved_chars Normally the "gen-delims" and "sub-delims" @@ -170,7 +171,7 @@ gboolean uri_str_to_bytes(const char *uri_str, GByteArray *bytes); * @see uri_str_to_bytes(), format_text(), isprint() */ WS_DLL_PUBLIC -const gchar* format_uri(const GByteArray *bytes, const gchar *reserved_chars); +gchar* format_uri(wmem_allocator_t* allocator, const GByteArray *bytes, const gchar *reserved_chars); /** Turn a OID string representation (dot notation) into a byte array. * |