diff options
author | John Thacker <johnthacker@gmail.com> | 2022-08-29 21:25:35 -0400 |
---|---|---|
committer | A Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2022-09-03 17:25:28 +0000 |
commit | 95b45b2555626729813578a1f5739820dc0acb33 (patch) | |
tree | bd15689e27165b196d3061f6fac06df165bf7d17 /epan/strutil.c | |
parent | faf05a82da36cf2b66766f8eff9b544cb3284233 (diff) |
Qt: Add percent-encoding to Show Packet Bytes
Add Percent-encoding to the list of encoding types that Show
Packet Bytes can handle.
There's a function added to glib 2.66 to handle this for arbitrary
bytes that might have internal nulls (and which allows the result
to be non UTF-8), but we don't require that version yet, so extend
the existing function.
Related to #1084
Diffstat (limited to 'epan/strutil.c')
-rw-r--r-- | epan/strutil.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/epan/strutil.c b/epan/strutil.c index 411ecdec96..b2c88d7fda 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -846,15 +846,19 @@ hex_str_to_bytes_encoding(const gchar *hex_str, GByteArray *bytes, const gchar * } /* - * Turn an RFC 3986 percent-encoded string into a byte array. + * Turn an RFC 3986 percent-encoded array of characters, not + * necessarily null-terminated, into a byte array. * XXX - We don't check for reserved characters. + * XXX - g_uri_unescape_bytes is superior, but limited to + * glib >= 2.66 */ #define HEX_DIGIT_BUF_LEN 3 gboolean -uri_str_to_bytes(const char *uri_str, GByteArray *bytes) +uri_to_bytes(const char *uri_str, GByteArray *bytes, size_t len) { guint8 val; - const gchar *p; + const gchar *p; + const gchar *uri_end = uri_str + len; gchar hex_digit[HEX_DIGIT_BUF_LEN]; g_byte_array_set_size(bytes, 0); @@ -864,7 +868,7 @@ uri_str_to_bytes(const char *uri_str, GByteArray *bytes) p = uri_str; - while (*p) { + while (p < uri_end) { if (!g_ascii_isprint(*p)) return FALSE; if (*p == '%') { @@ -888,6 +892,17 @@ uri_str_to_bytes(const char *uri_str, GByteArray *bytes) return TRUE; } +/* + * Turn an RFC 3986 percent-encoded string into a byte array. + * XXX - We don't check for reserved characters. + * XXX - Just use g_uri_unescape_string instead? + */ +gboolean +uri_str_to_bytes(const char *uri_str, GByteArray *bytes) +{ + return uri_to_bytes(uri_str, bytes, strlen(uri_str)); +} + /** * Create a copy of a GByteArray * |