Skip to content

Commit

Permalink
Fix potential leak in RSA method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Kwiatkowski authored and mtrojnar committed Oct 11, 2020
1 parent 9df104a commit 5caa277
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/p11_rsa.c
Expand Up @@ -352,6 +352,11 @@ int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
return meth->rsa_priv_dec;
}

static int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa)
{
return meth->finish;
}

#endif

static int pkcs11_rsa_priv_dec_method(int flen, const unsigned char *from,
Expand Down Expand Up @@ -383,6 +388,11 @@ static int pkcs11_rsa_priv_enc_method(int flen, const unsigned char *from,
static int pkcs11_rsa_free_method(RSA *rsa)
{
RSA_set_ex_data(rsa, rsa_ex_index, NULL);
int (*orig_rsa_free_method)(RSA *rsa) =
RSA_meth_get_finish(RSA_get_default_method());
if (orig_rsa_free_method) {
return orig_rsa_free_method(rsa);
}
return 1;
}

Expand Down

0 comments on commit 5caa277

Please sign in to comment.