diff options
author | tb <> | 2024-03-29 03:23:01 +0000 |
---|---|---|
committer | tb <> | 2024-03-29 03:23:01 +0000 |
commit | 2077b948490d2cc3e84f8bfb5437d5f061ce6703 (patch) | |
tree | cd0a757e30eddf86936b1c3b5caf38b04f930931 | |
parent | 203be6bbb69ba30845cd753c14dbc11d40254691 (diff) | |
download | openbsd-2077b948490d2cc3e84f8bfb5437d5f061ce6703.tar.gz openbsd-2077b948490d2cc3e84f8bfb5437d5f061ce6703.tar.bz2 openbsd-2077b948490d2cc3e84f8bfb5437d5f061ce6703.zip |
Improve error checking in i2d_ASN1_bio_stream()
The streaming BIO API is full of missing error checks. This diff reverts
the logic so that the single call to ASN1_item_i2d_bio() is error checked
(it has the usual 1/0 return values), unindents the bulk of the code and
propagates the SMIME_crlf_copy() return value (alos 1/0) to be the actual
error.
ok jsing
-rw-r--r-- | src/lib/libcrypto/asn1/asn_mime.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c index 56a428aec3..54185359a4 100644 --- a/src/lib/libcrypto/asn1/asn_mime.c +++ b/src/lib/libcrypto/asn1/asn_mime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn_mime.c,v 1.32 2023/07/05 21:23:36 beck Exp $ */ | 1 | /* $OpenBSD: asn_mime.c,v 1.33 2024/03/29 03:23:01 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -118,29 +118,30 @@ int | |||
118 | i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 118 | i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
119 | const ASN1_ITEM *it) | 119 | const ASN1_ITEM *it) |
120 | { | 120 | { |
121 | /* If streaming create stream BIO and copy all content through it */ | 121 | BIO *bio, *tbio; |
122 | if (flags & SMIME_STREAM) { | 122 | int ret; |
123 | BIO *bio, *tbio; | 123 | |
124 | bio = BIO_new_NDEF(out, val, it); | 124 | /* Without streaming, write out the ASN.1 structure's content. */ |
125 | if (!bio) { | 125 | if ((flags & SMIME_STREAM) == 0) |
126 | ASN1error(ERR_R_MALLOC_FAILURE); | 126 | return ASN1_item_i2d_bio(it, out, val); |
127 | return 0; | 127 | |
128 | } | 128 | /* If streaming, create a stream BIO and copy all content through it. */ |
129 | SMIME_crlf_copy(in, bio, flags); | 129 | if ((bio = BIO_new_NDEF(out, val, it)) == NULL) { |
130 | (void)BIO_flush(bio); | 130 | ASN1error(ERR_R_MALLOC_FAILURE); |
131 | /* Free up successive BIOs until we hit the old output BIO */ | 131 | return 0; |
132 | do { | ||
133 | tbio = BIO_pop(bio); | ||
134 | BIO_free(bio); | ||
135 | bio = tbio; | ||
136 | } while (bio != out); | ||
137 | } | 132 | } |
138 | /* else just write out ASN1 structure which will have all content | 133 | |
139 | * stored internally | 134 | ret = SMIME_crlf_copy(in, bio, flags); |
140 | */ | 135 | (void)BIO_flush(bio); |
141 | else | 136 | |
142 | ASN1_item_i2d_bio(it, out, val); | 137 | /* Free up successive BIOs until we hit the old output BIO. */ |
143 | return 1; | 138 | do { |
139 | tbio = BIO_pop(bio); | ||
140 | BIO_free(bio); | ||
141 | bio = tbio; | ||
142 | } while (bio != out); | ||
143 | |||
144 | return ret; | ||
144 | } | 145 | } |
145 | 146 | ||
146 | /* Base 64 read and write of ASN1 structure */ | 147 | /* Base 64 read and write of ASN1 structure */ |