From: Eugene Syromiatnikov Date: Thu, 17 Jul 2025 01:30:13 +0000 (+0200) Subject: crypto/mem.c: report realloc failures X-Git-Tag: openssl-3.6.0-alpha1~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a83b85333ce797c47743ac2fb7beadf58c1b3219;p=thirdparty%2Fopenssl.git crypto/mem.c: report realloc failures Seems like the case of realloc() returning NULL with non-zero size has been overlooked. Complements: 5639ee79bdc9 "ERR: Make CRYPTO_malloc() and friends report ERR_R_MALLOC_FAILURE" 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) --- diff --git a/crypto/mem.c b/crypto/mem.c index c37d563f55c..e39c10a54d1 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -292,6 +292,8 @@ void *CRYPTO_aligned_alloc(size_t num, size_t alignment, void **freeptr, 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); @@ -305,7 +307,12 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) } FAILTEST(); - return realloc(str, num); + ret = realloc(str, num); + + if (num != 0 && ret == NULL) + ossl_report_alloc_err(file, line); + + return ret; } void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,