From 26dc3d98369f290bd61e0fb41eb0f2ec91d686b6 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Fri, 25 Jul 2025 03:48:23 +0200 Subject: [PATCH] crypto/mem.c: report posix_memalign() errors in CRYPTO_aligned_alloc MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Report the errors for the known error codes returned by posix_memalign(). 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crypto/mem.c b/crypto/mem.c index a89b8719b6..5760724df7 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -248,8 +248,19 @@ void *CRYPTO_aligned_alloc(size_t num, size_t alignment, void **freeptr, /* Allow non-malloc() allocations as long as no malloc_impl is provided. */ if (malloc_impl == CRYPTO_malloc) { #if defined(_BSD_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) - if (posix_memalign(&ret, alignment, num)) - return NULL; + int memalign_ret; + + if ((memalign_ret = posix_memalign(&ret, alignment, num))) { + ret = NULL; + switch (memalign_ret) { + case EINVAL: + ossl_report_alloc_err_inv(file, line); + break; + case ENOMEM: + ossl_report_alloc_err(file, line); + break; + } + } *freeptr = ret; return ret; #endif -- 2.47.2