]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid leaking memory when realloc fails
authorFrederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Sun, 22 Dec 2024 12:35:00 +0000 (13:35 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 3 Jan 2025 14:58:26 +0000 (15:58 +0100)
In ossl_property_merge() we can drop the realloc because it just makes
the allocation smaller.

In quic-hq-interop.c we check the realloc result.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26244)

crypto/property/property_parse.c
demos/guide/quic-hq-interop.c

index dbe766d39f7ebe97873c72d954ace9fba1d9347f..613c285be82f8ac357b6125fb69238c871036a7f 100644 (file)
@@ -567,8 +567,7 @@ OSSL_PROPERTY_LIST *ossl_property_merge(const OSSL_PROPERTY_LIST *a,
         r->has_optional |= copy->optional;
     }
     r->num_properties = n;
-    if (n != t)
-        r = OPENSSL_realloc(r, sizeof(*r) + (n - 1) * sizeof(r->properties[0]));
+
     return r;
 }
 
index deb6b633e9ba3818c3371ebba64dc1722aa8462d..7c158fc09087a4e12769f3b2158ac1dcd3c512ad 100644 (file)
@@ -911,6 +911,8 @@ int main(int argc, char *argv[])
     while (req != NULL) {
         total_requests++;
         req_array = OPENSSL_realloc(req_array, sizeof(char *) * total_requests);
+        if (req_array == NULL)
+            goto end;
         req_array[total_requests - 1] = req;
         req = strtok(NULL, " ");
     }