]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libndr: Handle allocation failure
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 13 Feb 2023 01:58:23 +0000 (14:58 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 12 Apr 2023 13:52:31 +0000 (13:52 +0000)
If a talloc function returns NULL, indicating failure, the failure could
be masked by the next talloc call allocating on the NULL context.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
librpc/ndr/ndr_basic.c

index e239cfb27d9266dcd8b5f611b62728cccbf635e3..39aa3690cbe36fb6c1cca74d8584223f84a7c4f3 100644 (file)
@@ -1016,12 +1016,15 @@ _PUBLIC_ enum ndr_err_code ndr_pull_ipv6address(struct ndr_pull *ndr, int ndr_fl
        uint8_t addr[IPV6_BYTES];
        char *addr_str = talloc_strdup(ndr->current_mem_ctx, "");
        int i;
+       NDR_ERR_HAVE_NO_MEMORY(addr_str);
        NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
        for (i = 0; i < IPV6_BYTES; ++i) {
                addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]);
+               NDR_ERR_HAVE_NO_MEMORY(addr_str);
                /* We need a ':' every second byte but the last one */
                if (i%2 == 1 && i != (IPV6_BYTES - 1)) {
                        addr_str = talloc_strdup_append(addr_str, ":");
+                       NDR_ERR_HAVE_NO_MEMORY(addr_str);
                }
        }
        *address = addr_str;