diff options
author | tb <> | 2023-11-09 08:29:53 +0000 |
---|---|---|
committer | tb <> | 2023-11-09 08:29:53 +0000 |
commit | be423dedd29a6eb1dc4da38c241dc3a85eb9e271 (patch) | |
tree | 52b20f9d43bbe50d322dc5f0371f87bf773e84a2 /src | |
parent | 8262b39a51d36e26c823d43a1adeadbe3f6ef196 (diff) | |
download | openbsd-be423dedd29a6eb1dc4da38c241dc3a85eb9e271.tar.gz openbsd-be423dedd29a6eb1dc4da38c241dc3a85eb9e271.tar.bz2 openbsd-be423dedd29a6eb1dc4da38c241dc3a85eb9e271.zip |
Fix X509_ALGOR_set0() usage in rsa_alg_set_oaep_padding()
Replace X509_ALGOR_set0() with X509_ALGOR_set0_by_nid(). This way there
is no missing error checking for OBJ_nid2obj() and no nested functions.
Slightly more importantly, this plugs two long standing potential leaks
in this function (or previously rsa_cms_encrypt()) due to missing error
checking: in the unlikely event that X509_ALGOR_set0() failed, astr/ostr
would leak.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_ameth.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c index 46681c6348..228793b05c 100644 --- a/src/lib/libcrypto/rsa/rsa_ameth.c +++ b/src/lib/libcrypto/rsa/rsa_ameth.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_ameth.c,v 1.50 2023/11/09 08:20:10 tb Exp $ */ | 1 | /* $OpenBSD: rsa_ameth.c,v 1.51 2023/11/09 08:29:53 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -941,14 +941,16 @@ rsa_alg_set_oaep_padding(X509_ALGOR *alg, EVP_PKEY_CTX *pkey_ctx) | |||
941 | goto err; | 941 | goto err; |
942 | if (!ASN1_OCTET_STRING_set(ostr, label, labellen)) | 942 | if (!ASN1_OCTET_STRING_set(ostr, label, labellen)) |
943 | goto err; | 943 | goto err; |
944 | X509_ALGOR_set0(oaep->pSourceFunc, OBJ_nid2obj(NID_pSpecified), | 944 | if (!X509_ALGOR_set0_by_nid(oaep->pSourceFunc, NID_pSpecified, |
945 | V_ASN1_OCTET_STRING, ostr); | 945 | V_ASN1_OCTET_STRING, ostr)) |
946 | goto err; | ||
946 | ostr = NULL; | 947 | ostr = NULL; |
947 | } | 948 | } |
948 | 949 | ||
949 | if ((astr = ASN1_item_pack(oaep, &RSA_OAEP_PARAMS_it, NULL)) == NULL) | 950 | if ((astr = ASN1_item_pack(oaep, &RSA_OAEP_PARAMS_it, NULL)) == NULL) |
950 | goto err; | 951 | goto err; |
951 | X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaesOaep), V_ASN1_SEQUENCE, astr); | 952 | if (!X509_ALGOR_set0_by_nid(alg, NID_rsaesOaep, V_ASN1_SEQUENCE, astr)) |
953 | goto err; | ||
952 | astr = NULL; | 954 | astr = NULL; |
953 | 955 | ||
954 | ret = 1; | 956 | ret = 1; |