Plug leak in X509V3_add1_i2d()
authortb <tb@openbsd.org>
Sun, 24 Jul 2022 21:41:29 +0000 (21:41 +0000)
committertb <tb@openbsd.org>
Sun, 24 Jul 2022 21:41:29 +0000 (21:41 +0000)
Do not leak the extension that was deleted from the stack.

via OpenSSL c3efe5c9.

ok jsing

lib/libcrypto/x509/x509_lib.c

index a518d5b..e265d30 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: x509_lib.c,v 1.3 2021/11/01 20:53:08 tb Exp $ */
+/* $OpenBSD: x509_lib.c,v 1.4 2022/07/24 21:41:29 tb Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 1999.
  */
@@ -314,8 +314,9 @@ 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))
+                       if ((extmp = sk_X509_EXTENSION_delete(*x, extidx)) == NULL)
                                return -1;
+                       X509_EXTENSION_free(extmp);
                        return 1;
                }
        } else {