Fix a similar memory leak in SXNET_add_id_INTEGER
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 9 Jan 2024 14:05:30 +0000 (15:05 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 10 Jan 2024 17:16:19 +0000 (18:16 +0100)
Even in the good case there was memory leak here.
Add a simple test case to have at least some test coverage.

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 398011848468c7e8e481b295f7904afc30934217)

crypto/x509/v3_sxnet.c
test/recipes/25-test_req.t

index 5ad1040019fd43fd636d5b069433d7f0fc9e8662..d3eefccb8bfa247d1c9533d7704a7183c73a1359 100644 (file)
@@ -194,6 +194,7 @@ int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, const char *user,
         goto err;
     if (!sk_SXNETID_push(sx->ids, id))
         goto err;
+    ASN1_INTEGER_free(id->zone);
     id->zone = zone;
     *psx = sx;
     return 1;
index 8035add857bb8d4fc2b5f6193fcfa9042d109c50..16726e1a6785bafefb24d7fef6703a1cf5affae1 100644 (file)
@@ -15,7 +15,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
 
 setup("test_req");
 
-plan tests => 48;
+plan tests => 49;
 
 require_ok(srctop_file('test', 'recipes', 'tconversion.pl'));
 
@@ -52,6 +52,7 @@ ok(!run(app([@addext_args, "-addext", $val, "-addext", $val])));
 ok(!run(app([@addext_args, "-addext", $val, "-addext", $val2])));
 ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3])));
 ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3])));
+ok(run(app([@addext_args, "-addext", "SXNetID=1:one, 2:two, 3:three"])));
 
 # If a CSR is provided with neither of -key or -CA/-CAkey, this should fail.
 ok(!run(app(["openssl", "req", "-x509",