summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-03-29 03:23:02 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-03-29 03:23:02 +0000
commitb25296e48c2ff740d54c7d34cd289cee0f1d3861 (patch)
treea5caaaa73039a228b36c46ef0cd608d73679f3b7
parent4193f2f7f77d2820a97caa56a102e8b5829f9029 (diff)
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--lib/libcrypto/asn1/asn_mime.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/lib/libcrypto/asn1/asn_mime.c b/lib/libcrypto/asn1/asn_mime.c
index 56a428aec39..54185359a4e 100644
--- a/lib/libcrypto/asn1/asn_mime.c
+++ b/lib/libcrypto/asn1/asn_mime.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn_mime.c,v 1.32 2023/07/05 21:23:36 beck Exp $ */
+/* $OpenBSD: asn_mime.c,v 1.33 2024/03/29 03:23:01 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
@@ -118,29 +118,30 @@ int
i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
const ASN1_ITEM *it)
{
- /* If streaming create stream BIO and copy all content through it */
- if (flags & SMIME_STREAM) {
- BIO *bio, *tbio;
- bio = BIO_new_NDEF(out, val, it);
- if (!bio) {
- ASN1error(ERR_R_MALLOC_FAILURE);
- return 0;
- }
- SMIME_crlf_copy(in, bio, flags);
- (void)BIO_flush(bio);
- /* Free up successive BIOs until we hit the old output BIO */
- do {
- tbio = BIO_pop(bio);
- BIO_free(bio);
- bio = tbio;
- } while (bio != out);
+ BIO *bio, *tbio;
+ int ret;
+
+ /* Without streaming, write out the ASN.1 structure's content. */
+ if ((flags & SMIME_STREAM) == 0)
+ return ASN1_item_i2d_bio(it, out, val);
+
+ /* If streaming, create a stream BIO and copy all content through it. */
+ if ((bio = BIO_new_NDEF(out, val, it)) == NULL) {
+ ASN1error(ERR_R_MALLOC_FAILURE);
+ return 0;
}
- /* else just write out ASN1 structure which will have all content
- * stored internally
- */
- else
- ASN1_item_i2d_bio(it, out, val);
- return 1;
+
+ ret = SMIME_crlf_copy(in, bio, flags);
+ (void)BIO_flush(bio);
+
+ /* Free up successive BIOs until we hit the old output BIO. */
+ do {
+ tbio = BIO_pop(bio);
+ BIO_free(bio);
+ bio = tbio;
+ } while (bio != out);
+
+ return ret;
}
/* Base 64 read and write of ASN1 structure */