]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/mem.c: bump alignment to sizeof(void *) when posix_memaling() is used
authorEugene Syromiatnikov <esyr@openssl.org>
Thu, 31 Jul 2025 13:09:36 +0000 (15:09 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 8 Aug 2025 16:22:10 +0000 (12:22 -0400)
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 <esyr@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28059)

crypto/mem.c

index 5760724df7cc49c06734810cb745418a0e9879e1..6bdaca27f37281b4f968c7c5badda4113d3b195b 100644 (file)
@@ -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) {