diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-08-06 12:11:13 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2022-01-14 18:47:20 +0100 |
commit | 04bc3c1277b8b20dc29f96933f7be592c0535aa8 (patch) | |
tree | 3a4f2681b5f814177017771b87a07d67f5029302 /crypto/rsa | |
parent | EVP: fix evp_keymgmt_util_match so that it actually tries cross export the ot... (diff) | |
download | openssl-04bc3c1277b8b20dc29f96933f7be592c0535aa8.tar.xz openssl-04bc3c1277b8b20dc29f96933f7be592c0535aa8.zip |
Fix malloc failure handling of X509_ALGOR_set0()
Also update and slightly extend the respective documentation and simplify some code.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16251)
Diffstat (limited to 'crypto/rsa')
-rw-r--r-- | crypto/rsa/rsa_ameth.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index 043f509723..55b7216d63 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -636,23 +636,29 @@ static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, const void *asn, if (pad_mode == RSA_PKCS1_PADDING) return 2; if (pad_mode == RSA_PKCS1_PSS_PADDING) { - ASN1_STRING *os1 = NULL; - os1 = ossl_rsa_ctx_to_pss_string(pkctx); - if (!os1) + ASN1_STRING *os1 = ossl_rsa_ctx_to_pss_string(pkctx); + + if (os1 == NULL) return 0; /* Duplicate parameters if we have to */ - if (alg2) { + if (alg2 != NULL) { ASN1_STRING *os2 = ASN1_STRING_dup(os1); - if (!os2) { - ASN1_STRING_free(os1); - return 0; + + if (os2 == NULL) + goto err; + if (!X509_ALGOR_set0(alg2, OBJ_nid2obj(EVP_PKEY_RSA_PSS), + V_ASN1_SEQUENCE, os2)) { + ASN1_STRING_free(os2); + goto err; } - X509_ALGOR_set0(alg2, OBJ_nid2obj(EVP_PKEY_RSA_PSS), - V_ASN1_SEQUENCE, os2); } - X509_ALGOR_set0(alg1, OBJ_nid2obj(EVP_PKEY_RSA_PSS), - V_ASN1_SEQUENCE, os1); + if (!X509_ALGOR_set0(alg1, OBJ_nid2obj(EVP_PKEY_RSA_PSS), + V_ASN1_SEQUENCE, os1)) + goto err; return 3; + err: + ASN1_STRING_free(os1); + return 0; } return 2; } |