]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/mem.c: report posix_memalign() errors in CRYPTO_aligned_alloc
authorEugene Syromiatnikov <esyr@openssl.org>
Fri, 25 Jul 2025 01:48:23 +0000 (03:48 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 8 Aug 2025 16:22:10 +0000 (12:22 -0400)
Report the errors for the known error codes returned
by posix_memalign().

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 a89b8719b6e1b41f66527b5d84b1822a2b8236ab..5760724df7cc49c06734810cb745418a0e9879e1 100644 (file)
@@ -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