From d8404c981eba67969bbcf9f164449ff63d8b4649 Mon Sep 17 00:00:00 2001 From: tb <> Date: Tue, 7 Jan 2025 14:22:19 +0000 Subject: Rewrite TS_ASN1_INTEGER_print_bio() This eliminates another stupid BN_free(&bn) and uses BIO_printf() rather than a ludicrously silly result dance. In fact it appears that this dance was so hard to grok that OpenSSL misread it and made this function return the value -1 on ASN1_INTEGER_to_BN() failure, a value that it had never returned before. It doesn't matter anyway. The only uses of this function are internal to OpenSSL's code and since TS fully conforms to OpenSSL's high QA standards, no caller checks the return of TS_ASN1_INTEGER_print_bio(). ok jsing --- src/lib/libcrypto/ts/ts_lib.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/lib/libcrypto/ts/ts_lib.c b/src/lib/libcrypto/ts/ts_lib.c index 1e94922aa1..7e40101752 100644 --- a/src/lib/libcrypto/ts/ts_lib.c +++ b/src/lib/libcrypto/ts/ts_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ts_lib.c,v 1.14 2023/07/07 07:25:21 beck Exp $ */ +/* $OpenBSD: ts_lib.c,v 1.15 2025/01/07 14:22:19 tb Exp $ */ /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL * project 2002. */ @@ -74,20 +74,25 @@ int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num) { - BIGNUM num_bn; - int result = 0; - char *hex; - - BN_init(&num_bn); - ASN1_INTEGER_to_BN(num, &num_bn); - if ((hex = BN_bn2hex(&num_bn))) { - result = BIO_write(bio, "0x", 2) > 0; - result = result && BIO_write(bio, hex, strlen(hex)) > 0; - free(hex); - } - BN_free(&num_bn); + BIGNUM *bn = NULL; + char *hex = NULL; + int ret = 0; + + /* XXX - OpenSSL decided to return -1 here for some stupid reason. */ + if ((bn = ASN1_INTEGER_to_BN(num, NULL)) == NULL) + goto err; + if ((hex = BN_bn2hex(bn)) == NULL) + goto err; + if (BIO_printf(bio, "0x%s", hex) <= 0) + goto err; + + ret = 1; + + err: + BN_free(bn); + free(hex); - return result; + return ret; } LCRYPTO_ALIAS(TS_ASN1_INTEGER_print_bio); -- cgit v1.2.3-55-g6feb