summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-11-08 19:14:43 +0000
committertb <>2023-11-08 19:14:43 +0000
commitba06075ae7ae80b1695c4e112ed5f555d4d0b4aa (patch)
tree49798ce37006edf840e073195bd1a89710bba6a0 /src
parentda0e631ad5eb2a6fe875fba982ad3395843b0378 (diff)
downloadopenbsd-ba06075ae7ae80b1695c4e112ed5f555d4d0b4aa.tar.gz
openbsd-ba06075ae7ae80b1695c4e112ed5f555d4d0b4aa.tar.bz2
openbsd-ba06075ae7ae80b1695c4e112ed5f555d4d0b4aa.zip
Prepare further fixes of X509_ALGOR_set0() misuse
In rsa_alg_set_oaep_padding() rename los to ostr for consistency with astr, make it have function scope, free ostr in the error path and assume X509_ALGOR_set0() success. ok jca
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index 0558144dc7..cbdf7a36e9 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.47 2023/11/08 17:07:07 tb Exp $ */ 1/* $OpenBSD: rsa_ameth.c,v 1.48 2023/11/08 19:14:43 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 */
@@ -914,6 +914,7 @@ rsa_alg_set_oaep_padding(X509_ALGOR *alg, EVP_PKEY_CTX *pkey_ctx)
914 const EVP_MD *md, *mgf1md; 914 const EVP_MD *md, *mgf1md;
915 RSA_OAEP_PARAMS *oaep = NULL; 915 RSA_OAEP_PARAMS *oaep = NULL;
916 ASN1_STRING *astr = NULL; 916 ASN1_STRING *astr = NULL;
917 ASN1_OCTET_STRING *ostr = NULL;
917 unsigned char *label; 918 unsigned char *label;
918 int labellen; 919 int labellen;
919 int ret = 0; 920 int ret = 0;
@@ -937,19 +938,16 @@ rsa_alg_set_oaep_padding(X509_ALGOR *alg, EVP_PKEY_CTX *pkey_ctx)
937 /* XXX - why do we not set oaep->maskHash here? */ 938 /* XXX - why do we not set oaep->maskHash here? */
938 939
939 if (labellen > 0) { 940 if (labellen > 0) {
940 ASN1_OCTET_STRING *los;
941 oaep->pSourceFunc = X509_ALGOR_new(); 941 oaep->pSourceFunc = X509_ALGOR_new();
942 if (oaep->pSourceFunc == NULL) 942 if (oaep->pSourceFunc == NULL)
943 goto err; 943 goto err;
944 los = ASN1_OCTET_STRING_new(); 944 if ((ostr = ASN1_OCTET_STRING_new()) == NULL)
945 if (los == NULL)
946 goto err; 945 goto err;
947 if (!ASN1_OCTET_STRING_set(los, label, labellen)) { 946 if (!ASN1_OCTET_STRING_set(ostr, label, labellen))
948 ASN1_OCTET_STRING_free(los);
949 goto err; 947 goto err;
950 }
951 X509_ALGOR_set0(oaep->pSourceFunc, OBJ_nid2obj(NID_pSpecified), 948 X509_ALGOR_set0(oaep->pSourceFunc, OBJ_nid2obj(NID_pSpecified),
952 V_ASN1_OCTET_STRING, los); 949 V_ASN1_OCTET_STRING, ostr);
950 ostr = NULL;
953 } 951 }
954 /* create string with pss parameter encoding. */ 952 /* create string with pss parameter encoding. */
955 if ((astr = ASN1_item_pack(oaep, &RSA_OAEP_PARAMS_it, NULL)) == NULL) 953 if ((astr = ASN1_item_pack(oaep, &RSA_OAEP_PARAMS_it, NULL)) == NULL)
@@ -962,6 +960,7 @@ rsa_alg_set_oaep_padding(X509_ALGOR *alg, EVP_PKEY_CTX *pkey_ctx)
962 err: 960 err:
963 RSA_OAEP_PARAMS_free(oaep); 961 RSA_OAEP_PARAMS_free(oaep);
964 ASN1_STRING_free(astr); 962 ASN1_STRING_free(astr);
963 ASN1_OCTET_STRING_free(ostr);
965 964
966 return ret; 965 return ret;
967} 966}