From c3954054e10dc481c9d8ea9969bb4fe464613a80 Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 15 Jan 2022 04:02:37 +0000 Subject: [PATCH] Minor cleanup and simplification in dsa_pub_encode() This function has a weird dance of allocating an ASN1_STRING in an inner scope and assigning it to a void pointer in an outer scope for passing it to X509_PUBKEY_set0_param() and ASN1_STRING_free() on error. This can be simplified and streamlined. ok inoguchi --- lib/libcrypto/dsa/dsa_ameth.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/libcrypto/dsa/dsa_ameth.c b/lib/libcrypto/dsa/dsa_ameth.c index 5fff2890a2f..4e8f4ac8253 100644 --- a/lib/libcrypto/dsa/dsa_ameth.c +++ b/lib/libcrypto/dsa/dsa_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_ameth.c,v 1.31 2022/01/14 08:29:06 tb Exp $ */ +/* $OpenBSD: dsa_ameth.c,v 1.32 2022/01/15 04:02:37 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -134,31 +134,24 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) { DSA *dsa; ASN1_INTEGER *pubint = NULL; - void *pval = NULL; - int ptype; + ASN1_STRING *str = NULL; + int ptype = V_ASN1_UNDEF; unsigned char *penc = NULL; int penclen; dsa = pkey->pkey.dsa; if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { - ASN1_STRING *str; - - str = ASN1_STRING_new(); - if (str == NULL) { + if ((str = ASN1_STRING_new()) == NULL) { DSAerror(ERR_R_MALLOC_FAILURE); goto err; } str->length = i2d_DSAparams(dsa, &str->data); if (str->length <= 0) { DSAerror(ERR_R_MALLOC_FAILURE); - ASN1_STRING_free(str); goto err; } - pval = str; ptype = V_ASN1_SEQUENCE; - } else - ptype = V_ASN1_UNDEF; - + } if ((pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) { DSAerror(ERR_R_MALLOC_FAILURE); @@ -173,13 +166,13 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) goto err; } - if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, pval, + if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, str, penc, penclen)) return 1; -err: + err: free(penc); - ASN1_STRING_free(pval); + ASN1_STRING_free(str); return 0; } -- 2.20.1