diff options
author | tb <> | 2025-01-07 14:22:19 +0000 |
---|---|---|
committer | tb <> | 2025-01-07 14:22:19 +0000 |
commit | d8404c981eba67969bbcf9f164449ff63d8b4649 (patch) | |
tree | 12dba5a12c4c0b1322a9318a804ee7ddcaf94b5a | |
parent | 8af017c4e7dd8e8ee124c5cb7bc8370f1f2d179c (diff) | |
download | openbsd-d8404c981eba67969bbcf9f164449ff63d8b4649.tar.gz openbsd-d8404c981eba67969bbcf9f164449ff63d8b4649.tar.bz2 openbsd-d8404c981eba67969bbcf9f164449ff63d8b4649.zip |
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
-rw-r--r-- | src/lib/libcrypto/ts/ts_lib.c | 33 |
1 files 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 @@ | |||
1 | /* $OpenBSD: ts_lib.c,v 1.14 2023/07/07 07:25:21 beck Exp $ */ | 1 | /* $OpenBSD: ts_lib.c,v 1.15 2025/01/07 14:22:19 tb Exp $ */ |
2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL | 2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL |
3 | * project 2002. | 3 | * project 2002. |
4 | */ | 4 | */ |
@@ -74,20 +74,25 @@ | |||
74 | int | 74 | int |
75 | TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num) | 75 | TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num) |
76 | { | 76 | { |
77 | BIGNUM num_bn; | 77 | BIGNUM *bn = NULL; |
78 | int result = 0; | 78 | char *hex = NULL; |
79 | char *hex; | 79 | int ret = 0; |
80 | 80 | ||
81 | BN_init(&num_bn); | 81 | /* XXX - OpenSSL decided to return -1 here for some stupid reason. */ |
82 | ASN1_INTEGER_to_BN(num, &num_bn); | 82 | if ((bn = ASN1_INTEGER_to_BN(num, NULL)) == NULL) |
83 | if ((hex = BN_bn2hex(&num_bn))) { | 83 | goto err; |
84 | result = BIO_write(bio, "0x", 2) > 0; | 84 | if ((hex = BN_bn2hex(bn)) == NULL) |
85 | result = result && BIO_write(bio, hex, strlen(hex)) > 0; | 85 | goto err; |
86 | free(hex); | 86 | if (BIO_printf(bio, "0x%s", hex) <= 0) |
87 | } | 87 | goto err; |
88 | BN_free(&num_bn); | 88 | |
89 | ret = 1; | ||
90 | |||
91 | err: | ||
92 | BN_free(bn); | ||
93 | free(hex); | ||
89 | 94 | ||
90 | return result; | 95 | return ret; |
91 | } | 96 | } |
92 | LCRYPTO_ALIAS(TS_ASN1_INTEGER_print_bio); | 97 | LCRYPTO_ALIAS(TS_ASN1_INTEGER_print_bio); |
93 | 98 | ||