]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/mem.c: report realloc_impl failures
authorEugene Syromiatnikov <esyr@openssl.org>
Thu, 31 Jul 2025 12:34:21 +0000 (14:34 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 8 Aug 2025 16:22:10 +0000 (12:22 -0400)
Analogous to the way CRYPTO_malloc does it.

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 e39c10a54d1e2d19ad1b4a5293e2c41a538f6e4f..48da037af31857b3c654a252a01aba7b174fde3a 100644 (file)
@@ -295,8 +295,14 @@ 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);
+    if (realloc_impl != CRYPTO_realloc) {
+        ret = realloc_impl(str, num, file, line);
+
+        if (num == 0 || ret != NULL)
+            return ret;
+
+        goto err;
+    }
 
     if (str == NULL)
         return CRYPTO_malloc(num, file, line);
@@ -309,6 +315,7 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
     FAILTEST();
     ret = realloc(str, num);
 
+err:
     if (num != 0 && ret == NULL)
         ossl_report_alloc_err(file, line);