From 313c12125e37fabcb7eca57da5bc3d00b1a356dd Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Thu, 31 Jul 2025 14:34:21 +0200 Subject: [PATCH] crypto/mem.c: report realloc_impl failures MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Analogous to the way CRYPTO_malloc does it. Signed-off-by: Eugene Syromiatnikov Reviewed-by: Saša Nedvědický Reviewed-by: Matt Caswell Reviewed-by: Paul Dale Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28059) --- crypto/mem.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crypto/mem.c b/crypto/mem.c index e39c10a54d..48da037af3 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -295,8 +295,14 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) void *ret; INCREMENT(realloc_count); - if (realloc_impl != CRYPTO_realloc) - return realloc_impl(str, num, file, line); + if (realloc_impl != CRYPTO_realloc) { + ret = realloc_impl(str, num, file, line); + + if (num == 0 || ret != NULL) + return ret; + + goto err; + } if (str == NULL) return CRYPTO_malloc(num, file, line); @@ -309,6 +315,7 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) FAILTEST(); ret = realloc(str, num); +err: if (num != 0 && ret == NULL) ossl_report_alloc_err(file, line); -- 2.47.2