diff options
author | Gerald Combs <gerald@wireshark.org> | 2022-01-28 14:02:15 -0800 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2022-01-28 14:02:15 -0800 |
commit | 451e3cc4efdc422118b0099175b0087d59323489 (patch) | |
tree | b37f7ecbf41ba47273ce2e77ee0329c9b04d8c9f /epan/dissectors/packet-dns.c | |
parent | 899b07a8eb8f1b1e44b52a48fced30aa19d55009 (diff) |
DNS: Check our NSEC3 hash length.
Add a next hashed owner field only if we have one. Use a wmem_strbuf.
Fixes #17912.
Diffstat (limited to 'epan/dissectors/packet-dns.c')
-rw-r--r-- | epan/dissectors/packet-dns.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/epan/dissectors/packet-dns.c b/epan/dissectors/packet-dns.c index 9d2675951b..9cd3417c7c 100644 --- a/epan/dissectors/packet-dns.c +++ b/epan/dissectors/packet-dns.c @@ -3347,11 +3347,6 @@ dissect_dns_answer(tvbuff_t *tvb, int offsetx, int dns_data_offset, proto_item *flags_item, *hash_item; proto_tree *flags_tree; - /* Base 32 Encoding with Extended Hex Alphabet (see RFC 4648 section 7) */ - const char *base32hex = "0123456789abcdefghijklmnopqrstuv"; - char *hash_value_base32hex; - int group, in_offset, out_offset; - proto_tree_add_item(rr_tree, hf_dns_nsec3_algo, tvb, cur_offset, 1, ENC_BIG_ENDIAN); cur_offset += 1; @@ -3379,16 +3374,21 @@ dissect_dns_answer(tvbuff_t *tvb, int offsetx, int dns_data_offset, * characters ("=") are not used in the NSEC3 specification (see RFC 5155 * section 1.3). */ - hash_value_base32hex = (char *)wmem_alloc0(wmem_packet_scope(), hash_len * 2); - for (in_offset = 0, out_offset = 0; - in_offset / 8 < hash_len; - in_offset += 5, out_offset += 1) { - group = tvb_get_bits8(tvb, cur_offset * 8 + in_offset, 5); - hash_value_base32hex[out_offset] = base32hex[group]; + if (hash_len) { + /* Base 32 Encoding with Extended Hex Alphabet (see RFC 4648 section 7) */ + const char *base32hex = "0123456789abcdefghijklmnopqrstuv"; + wmem_strbuf_t *hash_value_base32hex = wmem_strbuf_new(pinfo->pool, ""); + int group, in_offset, out_offset; + for (in_offset = 0, out_offset = 0; + in_offset / 8 < hash_len; + in_offset += 5, out_offset += 1) { + group = tvb_get_bits8(tvb, cur_offset * 8 + in_offset, 5); + wmem_strbuf_append_c(hash_value_base32hex, base32hex[group]); + } + hash_item = proto_tree_add_string(rr_tree, hf_dns_nsec3_hash_value, tvb, cur_offset, hash_len, wmem_strbuf_finalize(hash_value_base32hex)); + proto_item_set_generated(hash_item); + cur_offset += hash_len; } - hash_item = proto_tree_add_string(rr_tree, hf_dns_nsec3_hash_value, tvb, cur_offset, hash_len, hash_value_base32hex); - proto_item_set_generated(hash_item); - cur_offset += hash_len; rr_len = data_len - (cur_offset - initial_offset); dissect_type_bitmap(rr_tree, tvb, cur_offset, rr_len); |