]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ndr: pull_dns_string: drop nbt/dns mem_ctx difference
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 20 May 2020 07:18:14 +0000 (19:18 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 16 Apr 2026 00:54:43 +0000 (00:54 +0000)
Until now NBT and DNS have used talloc contexts of different lifetimes
to allocate component strings. The actual talloc context doesn't
really matter -- these strings are immediately copied and can be freed
straight after. So that is what we do.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14378

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
librpc/ndr/ndr_dns_utils.c

index 00b7f8ce86aaf72499456dc5d49e7054f2883b68..975a5c496cf1dedb790dbe0682462071708bfcd2 100644 (file)
@@ -12,7 +12,6 @@
   pull one component of a dns/nbt string
 */
 static enum ndr_err_code ndr_pull_component(struct ndr_pull *ndr,
-                                           TALLOC_CTX *mem_ctx,
                                            uint8_t **component,
                                            uint32_t *offset,
                                            uint32_t *max_offset,
@@ -60,7 +59,7 @@ static enum ndr_err_code ndr_pull_component(struct ndr_pull *ndr,
                                              "length too long",
                                              err_name);
                }
-               *component = (uint8_t*)talloc_strndup(mem_ctx,
+               *component = (uint8_t*)talloc_strndup(ndr,
                                (const char *)&ndr->data[1 + *offset], len);
                NDR_ERR_HAVE_NO_MEMORY(*component);
                *offset += len + 1;
@@ -87,14 +86,11 @@ enum ndr_err_code ndr_pull_dns_string_list(struct ndr_pull *ndr,
        unsigned num_components;
        char *name;
        const char *err_name = NULL;
-       TALLOC_CTX *mem_ctx = NULL;
 
        if (is_nbt) {
                err_name = "NBT";
-               mem_ctx = ndr->current_mem_ctx;
        } else {
                err_name = "DNS";
-               mem_ctx = ndr;
        }
 
        if (!(ndr_flags & NDR_SCALARS)) {
@@ -109,7 +105,6 @@ enum ndr_err_code ndr_pull_dns_string_list(struct ndr_pull *ndr,
             num_components++) {
                uint8_t *component = NULL;
                NDR_CHECK(ndr_pull_component(ndr,
-                                            mem_ctx,
                                             &component, &offset,
                                             &max_offset,
                                             err_name));
@@ -124,6 +119,7 @@ enum ndr_err_code ndr_pull_dns_string_list(struct ndr_pull *ndr,
                                                             component);
                }
                NDR_ERR_HAVE_NO_MEMORY(name);
+               TALLOC_FREE(component);
        }
        if (num_components == MAX_COMPONENTS) {
                return ndr_pull_error(ndr, NDR_ERR_STRING,