Check the return values of RSA_public_encrypt and RSA_private_decrypt functions appropriately.
Signed-off-by: Ramon de Carvalho Valle <[email protected]> --- usr/lib/pkcs11/soft_stdll/soft_specific.c | 35 +++++++++++++++------------- 1 files changed, 19 insertions(+), 16 deletions(-) diff --git a/usr/lib/pkcs11/soft_stdll/soft_specific.c b/usr/lib/pkcs11/soft_stdll/soft_specific.c index 90d20fd..1bf47c4 100644 --- a/usr/lib/pkcs11/soft_stdll/soft_specific.c +++ b/usr/lib/pkcs11/soft_stdll/soft_specific.c @@ -1100,27 +1100,29 @@ token_specific_rsa_encrypt( CK_BYTE * in_data, { CK_RV rc; RSA *rsa; + int size; // Convert the local representation to an RSA representation rsa = (RSA *)rsa_convert_public_key(key_obj); if (rsa==NULL) { st_err_log(4, __FILE__, __LINE__, __FUNCTION__); rc = CKR_FUNCTION_FAILED; - goto done; + return rc; } // Do an RSA public encryption - rc = RSA_public_encrypt(in_data_len, in_data, out_data, rsa, RSA_NO_PADDING); + size = RSA_public_encrypt(in_data_len, in_data, out_data, rsa, RSA_NO_PADDING); - if (rc != 0) { - rc = CKR_OK; - } else { + if (size == -1) { st_err_log(4, __FILE__, __LINE__, __FUNCTION__); rc = CKR_FUNCTION_FAILED; + goto done; } - // Clean up after ourselves - RSA_free(rsa); + + rc = CKR_OK; + done: - return rc; + RSA_free(rsa); + return rc; } @@ -1132,28 +1134,29 @@ token_specific_rsa_decrypt( CK_BYTE * in_data, { CK_RV rc; RSA *rsa; + int size; // Convert the local key representation to an RSA key representaion rsa = (RSA *)rsa_convert_private_key(key_obj); if (rsa == NULL) { st_err_log(4, __FILE__, __LINE__, __FUNCTION__); rc = CKR_FUNCTION_FAILED; - goto done; + return rc; } // Do the private decryption - rc = RSA_private_decrypt(in_data_len, in_data, out_data, rsa, RSA_NO_PADDING); + size = RSA_private_decrypt(in_data_len, in_data, out_data, rsa, RSA_NO_PADDING); - if (rc != 0) { - rc = CKR_OK; - } else { + if (size == -1) { st_err_log(4, __FILE__, __LINE__, __FUNCTION__); rc = CKR_FUNCTION_FAILED; + goto done; } - // Clean up - RSA_free(rsa); + rc = CKR_OK; + done: - return rc; + RSA_free(rsa); + return rc; } CK_RV -- 1.7.0.4 ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Opencryptoki-tech mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech
