From: Volker Lendecke Date: Thu, 12 Dec 2024 14:17:05 +0000 (+0100) Subject: lib: Fix error path memleaks in read_ea_list_entry() X-Git-Tag: tdb-1.4.13~274 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff4c70e03aebd9c1b54741d28154468029f7e887;p=thirdparty%2Fsamba.git lib: Fix error path memleaks in read_ea_list_entry() Don't leak the result on error Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Wed Dec 18 09:30:33 UTC 2024 on atb-devel-224 --- diff --git a/source3/lib/util_ea.c b/source3/lib/util_ea.c index 92761f29c85..b0b6726c3ee 100644 --- a/source3/lib/util_ea.c +++ b/source3/lib/util_ea.c @@ -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; } /****************************************************************************