summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-01-31 08:29:53 -0500
committerMichael Mann <mmann78@netscape.net>2017-01-31 17:08:54 +0000
commit148fb1acf46e205801e4e06f4f3f755a13bd2a48 (patch)
tree7fac7a3cf2e986a2ac22f9637f6b4fdd73aae392
parent51a30142251e377ec28eb8584c56386c2481d6c0 (diff)
downloadwireshark-148fb1acf46e205801e4e06f4f3f755a13bd2a48.tar.gz
Add wmem allocator parameter to format_uri
Change-Id: Ic6de84a37b501e9c62a7d37071b2b081a1a1dd50 Reviewed-on: https://code.wireshark.org/review/19885 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--epan/crypt/airpdcap.c7
-rw-r--r--epan/strutil.c35
-rw-r--r--epan/strutil.h3
-rw-r--r--ui/gtk/airpcap_gui_utils.c19
4 files changed, 33 insertions, 31 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.
*
diff --git a/ui/gtk/airpcap_gui_utils.c b/ui/gtk/airpcap_gui_utils.c
index 61fa4cd6bd..c1341eda32 100644
--- a/ui/gtk/airpcap_gui_utils.c
+++ b/ui/gtk/airpcap_gui_utils.c
@@ -1569,7 +1569,7 @@ airpcap_add_key_to_list(GtkListStore *key_list_store, gchar* type, gchar* key, g
void
airpcap_fill_key_list(GtkListStore *key_list_store)
{
- const gchar* s = NULL;
+ gchar* s = NULL;
unsigned int i,n;
airpcap_if_info_t* fake_if_info;
GList* wireshark_key_list = NULL;
@@ -1597,16 +1597,23 @@ airpcap_fill_key_list(GtkListStore *key_list_store)
else if (curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
{
if (curr_key->ssid != NULL)
- s = format_uri(curr_key->ssid, ":");
+ {
+ s = format_uri(NULL, curr_key->ssid, ":");
+ gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
+ KL_COL_TYPE, AIRPCAP_WPA_PWD_KEY_STRING,
+ KL_COL_KEY, curr_key->key->str,
+ KL_COL_SSID, s,
+ -1);
+ wmem_free(NULL, s);
+ }
else
- s = "";
-
+ {
gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
KL_COL_TYPE, AIRPCAP_WPA_PWD_KEY_STRING,
KL_COL_KEY, curr_key->key->str,
- KL_COL_SSID, s,
+ KL_COL_SSID, "",
-1);
-
+ }
}
else if (curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
{