Blame SOURCES/openssl-pkcs11-0.4.10-fix-potential-leak-in-rsa-method.patch

45dc05
From d2f900a51de27f2d9229b0ae785c02ac272bd525 Mon Sep 17 00:00:00 2001
45dc05
From: Mateusz Kwiatkowski <m.kwiatkowski@avsystem.com>
45dc05
Date: Thu, 10 Sep 2020 15:47:41 +0200
45dc05
Subject: [PATCH] Fix potential leak in RSA method
45dc05
45dc05
Upstream-Status: Backport [https://github.com/OpenSC/libp11/commit/5caa2779762c3d760f33b70cd9e1f70f15f3ea57]
45dc05
---
45dc05
 src/p11_rsa.c | 10 ++++++++++
45dc05
 1 file changed, 10 insertions(+)
45dc05
45dc05
diff --git a/src/p11_rsa.c b/src/p11_rsa.c
45dc05
index 221513c7..b6beef0b 100644
45dc05
--- a/src/p11_rsa.c
45dc05
+++ b/src/p11_rsa.c
45dc05
@@ -352,6 +352,11 @@ int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
45dc05
     return meth->rsa_priv_dec;
45dc05
 }
45dc05
 
45dc05
+static int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
45dc05
+{
45dc05
+    return meth->finish;
45dc05
+}
45dc05
+
45dc05
 #endif
45dc05
 
45dc05
 static int pkcs11_rsa_priv_dec_method(int flen, const unsigned char *from,
45dc05
@@ -383,6 +388,11 @@ static int pkcs11_rsa_priv_enc_method(int flen, const unsigned char *from,
45dc05
 static int pkcs11_rsa_free_method(RSA *rsa)
45dc05
 {
45dc05
 	RSA_set_ex_data(rsa, rsa_ex_index, NULL);
45dc05
+	int (*orig_rsa_free_method)(RSA *rsa) =
45dc05
+		RSA_meth_get_finish(RSA_get_default_method());
45dc05
+	if (orig_rsa_free_method) {
45dc05
+		return orig_rsa_free_method(rsa);
45dc05
+	}
45dc05
 	return 1;
45dc05
 }
45dc05