]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/mem.c: report realloc failures
authorEugene Syromiatnikov <esyr@openssl.org>
Thu, 17 Jul 2025 01:30:13 +0000 (03:30 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 8 Aug 2025 16:22:10 +0000 (12:22 -0400)
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 <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 c37d563f55cb5ff0b0f0666e57dc99537e8db8a6..e39c10a54d1e2d19ad1b4a5293e2c41a538f6e4f 100644 (file)
@@ -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,