]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Fix error path memleaks in read_ea_list_entry()
authorVolker Lendecke <vl@samba.org>
Thu, 12 Dec 2024 14:17:05 +0000 (15:17 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 18 Dec 2024 09:30:33 +0000 (09:30 +0000)
Don't leak the result on error

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Wed Dec 18 09:30:33 UTC 2024 on atb-devel-224

source3/lib/util_ea.c

index 92761f29c8552d7f450c8e5bd07ee5f9eeb0ef69..b0b6726c3ee13add5f474b0a915f0a1b69da49f1 100644 (file)
@@ -33,11 +33,11 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da
        size_t converted_size;
 
        if (!eal) {
-               return NULL;
+               goto fail;
        }
 
        if (data_size < 6) {
-               return NULL;
+               goto fail;
        }
 
        eal->ea.flags = CVAL(pdata,0);
@@ -45,23 +45,23 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da
        val_len = SVAL(pdata,2);
 
        if (4 + namelen + 1 + val_len > data_size) {
-               return NULL;
+               goto fail;
        }
 
        /* Ensure the name is null terminated. */
        if (pdata[namelen + 4] != '\0') {
-               return NULL;
+               goto fail;
        }
        if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) {
                DBG_ERR("pull_ascii_talloc failed: %s\n", strerror(errno));
        }
        if (!eal->ea.name) {
-               return NULL;
+               goto fail;
        }
 
        eal->ea.value = data_blob_talloc(eal, NULL, (size_t)val_len + 1);
        if (!eal->ea.value.data) {
-               return NULL;
+               goto fail;
        }
 
        memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);
@@ -79,6 +79,9 @@ struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t da
        dump_data(10, eal->ea.value.data, eal->ea.value.length);
 
        return eal;
+fail:
+       TALLOC_FREE(eal);
+       return NULL;
 }
 
 /****************************************************************************