From 68a714b95785bca734ba1c846ae37655b86af768 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 11 Oct 2024 06:13:09 +0000 Subject: [PATCH] Clean up i2d_ECPKParameters() Use better variable names and turn it into single-exit. This changes the behavior slightly in that an error is pushed onto the stack also for i2d_ECPKPARAMETERS() return values < 0. ok jsing --- lib/libcrypto/ec/ec_asn1.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/libcrypto/ec/ec_asn1.c b/lib/libcrypto/ec/ec_asn1.c index 825f4f38928..d6b92fb16d1 100644 --- a/lib/libcrypto/ec/ec_asn1.c +++ b/lib/libcrypto/ec/ec_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_asn1.c,v 1.57 2024/10/03 05:07:49 tb Exp $ */ +/* $OpenBSD: ec_asn1.c,v 1.58 2024/10/11 06:13:09 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -1034,21 +1034,24 @@ d2i_ECPKParameters(EC_GROUP **a, const unsigned char **in, long len) LCRYPTO_ALIAS(d2i_ECPKParameters); int -i2d_ECPKParameters(const EC_GROUP *a, unsigned char **out) +i2d_ECPKParameters(const EC_GROUP *group, unsigned char **out_der) { + ECPKPARAMETERS *parameters; int ret = 0; - ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL); - if (tmp == NULL) { + + if ((parameters = ec_asn1_group2pkparameters(group, NULL)) == NULL) { ECerror(EC_R_GROUP2PKPARAMETERS_FAILURE); - return 0; + goto err; } - if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) { + if ((ret = i2d_ECPKPARAMETERS(parameters, out_der)) <= 0) { ECerror(EC_R_I2D_ECPKPARAMETERS_FAILURE); - ECPKPARAMETERS_free(tmp); - return 0; + goto err; } - ECPKPARAMETERS_free(tmp); - return (ret); + + err: + ECPKPARAMETERS_free(parameters); + + return ret; } LCRYPTO_ALIAS(i2d_ECPKParameters); -- 2.20.1