Fix memory leak in X509V3_add1_i2d when flag is X509V3_ADD_DELETE
authorAllan <allanchang96@gmail.com>
Thu, 7 Jul 2022 23:04:09 +0000 (16:04 -0700)
committerTomas Mraz <tomas@openssl.org>
Mon, 11 Jul 2022 08:50:56 +0000 (10:50 +0200)
Fixes #18677

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18698)

crypto/x509/v3_lib.c

index 42b6ff15277e199ea7a014138b9bced84473c60a..5c05b56d9c7fdd560942f8ab23c59473fc8aa29b 100644 (file)
@@ -242,8 +242,10 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
         }
         /* If delete, just delete it */
         if (ext_op == X509V3_ADD_DELETE) {
-            if (!sk_X509_EXTENSION_delete(*x, extidx))
+            extmp = sk_X509_EXTENSION_delete(*x, extidx);
+            if (extmp == NULL)
                 return -1;
+            X509_EXTENSION_free(extmp);
             return 1;
         }
     } else {