HTTP2: Ensure that the unescaped header value is valid encoding

It's possible, in the case of errors, for the result of
g_uri_unescape_string not to be valid UTF-8, either if originally
some other encoding was percent-encoded, or if there were errors.
Check for it.

Fix #18658.
This commit is contained in:
John Thacker 2022-11-19 07:28:40 -05:00 committed by A Wireshark GitLab Utility
parent 79c3a77752
commit 92208e4330
1 changed files with 9 additions and 1 deletions

View File

@ -2171,7 +2171,15 @@ inflate_http2_header_block(tvbuff_t *tvb, packet_info *pinfo, guint offset, prot
/* Add header unescaped. */
header_unescaped = g_uri_unescape_string(header_value, NULL);
if (header_unescaped != NULL) {
ti = proto_tree_add_string(header_tree, hf_http2_header_unescaped, header_tvb, hoffset, header_value_length, header_unescaped);
if (g_utf8_validate(header_unescaped, -1, NULL)) {
ti = proto_tree_add_string(header_tree, hf_http2_header_unescaped, header_tvb, hoffset, header_value_length, header_unescaped);
} else {
gchar* header_unescaped_valid = g_utf8_make_valid(header_unescaped, -1);
if (header_unescaped_valid != NULL) {
ti = proto_tree_add_string(header_tree, hf_http2_header_unescaped, header_tvb, hoffset, header_value_length, header_unescaped_valid);
g_free(header_unescaped_valid);
}
}
proto_item_set_generated(ti);
g_free(header_unescaped);
}