From ff3caae4d288c27b4268a3e55fb94a5abeff5881 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Thu, 31 Jul 2025 15:09:36 +0200 Subject: [PATCH] crypto/mem.c: bump alignment to sizeof(void *) when posix_memaling() is used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Per [1]: The value of alignment shall be a power of two multiple of sizeof(void *). [1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_memalign.html 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto/mem.c b/crypto/mem.c index 5760724df7..6bdaca27f3 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -250,6 +250,10 @@ void *CRYPTO_aligned_alloc(size_t num, size_t alignment, void **freeptr, #if defined(_BSD_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) int memalign_ret; + /* posix_memalign() requires alignment to be at least sizeof(void *) */ + if (alignment < sizeof(void *)) + alignment = sizeof(void *); + if ((memalign_ret = posix_memalign(&ret, alignment, num))) { ret = NULL; switch (memalign_ret) { -- 2.47.2