Fix a possible memory leak in sxnet_v2i
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 8 Jan 2024 14:31:32 +0000 (15:31 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 10 Jan 2024 17:14:37 +0000 (18:14 +0100)
When a subsequent call to SXNET_add_id_asc fails
e.g. because user is a string larger than 64 char
or the zone is a duplicate zone id,
or the zone is not an integer,
a memory leak may be the result.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23234)

(cherry picked from commit 0151e772195fc03cce0f12e5e266e51dc15243a0)

crypto/x509/v3_sxnet.c

index 09e16956b61104c7015099a50294f5f1c3378c98..5ad1040019fd43fd636d5b069433d7f0fc9e8662 100644 (file)
@@ -103,8 +103,10 @@ static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
     int i;
     for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
         cnf = sk_CONF_VALUE_value(nval, i);
-        if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
+        if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) {
+            SXNET_free(sx);
             return NULL;
+       }
     }
     return sx;
 }