From 8045e8039085cf6bdf3c010788fccb9cd2242cd3 Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 2 Jul 2023 14:53:18 +0000 Subject: [PATCH] Use asprintf() to avoid repetition in string constants ... since ASN1_bn_print() is stupid. ok jsing --- lib/libcrypto/ec/eck_prn.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/libcrypto/ec/eck_prn.c b/lib/libcrypto/ec/eck_prn.c index 9bf05bb38c1..598b83835f1 100644 --- a/lib/libcrypto/ec/eck_prn.c +++ b/lib/libcrypto/ec/eck_prn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eck_prn.c,v 1.23 2023/07/02 13:48:47 tb Exp $ */ +/* $OpenBSD: eck_prn.c,v 1.24 2023/07/02 14:53:18 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -203,7 +203,9 @@ ecpk_print_explicit_parameters(BIO *bp, const EC_GROUP *group, int off) BIGNUM *p, *a, *b, *order, *cofactor; BIGNUM *gen = NULL; const EC_POINT *generator; - const unsigned char *conversion, *seed; + const char *conversion_form; + char *conversion = NULL; + const unsigned char *seed; size_t seed_len; unsigned char *buffer = NULL; size_t buf_len, i; @@ -286,13 +288,17 @@ ecpk_print_explicit_parameters(BIO *bp, const EC_GROUP *group, int off) goto err; if (form == POINT_CONVERSION_COMPRESSED) - conversion = "Generator (compressed):"; + conversion_form = "compressed"; else if (form == POINT_CONVERSION_UNCOMPRESSED) - conversion = "Generator (uncompressed):"; + conversion_form = "compressed"; else if (form == POINT_CONVERSION_HYBRID) - conversion = "Generator (hybrid):"; + conversion_form = "hybrid"; else - conversion = "Generator (unknown):"; + conversion_form = "unknown"; + if (asprintf(&conversion, "Generator (%s):", conversion_form) == -1) { + conversion = NULL; + goto err; + } if (!ASN1_bn_print(bp, conversion, gen, buffer, off)) goto err; @@ -311,6 +317,7 @@ err: BN_CTX_end(ctx); BN_CTX_free(ctx); free(buffer); + free(conversion); return ret; } -- 2.20.1