From 999bce720fcefb0109368f942d5170c1c98dd5a6 Mon Sep 17 00:00:00 2001 From: Joshua Rogers Date: Sat, 11 Oct 2025 20:10:48 +0800 Subject: [PATCH] SMIME_text() and SMIME_crlf_copy() small refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When out is NULL, SMIME_text() now skips BIO_write entirely and continues to return success based on the read loop result. This matches existing and expected semantics while avoiding a pointless write and any error masking. Signed-off-by: Joshua Rogers Reviewed-by: Saša Nedvědický Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/28879) --- crypto/asn1/asn_mime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 2c419eb6ea5..b85f734e667 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -566,7 +566,7 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) out = BIO_push(bf, out); if (flags & SMIME_BINARY) { while ((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) { - if (BIO_write(out, linebuf, len) != len && out != NULL) + if (BIO_write(out, linebuf, len) != len) goto err; } } else { @@ -586,7 +586,7 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) goto err; eolcnt = 0; } - if (BIO_write(out, linebuf, len) != len && out != NULL) + if (BIO_write(out, linebuf, len) != len) goto err; if (eol && BIO_puts(out, "\r\n") < 0) goto err; @@ -633,7 +633,7 @@ int SMIME_text(BIO *in, BIO *out) } sk_MIME_HEADER_pop_free(headers, mime_hdr_free); while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) - if (BIO_write(out, iobuf, len) != len && out != NULL) + if (out != NULL && BIO_write(out, iobuf, len) != len) return 0; return len >= 0; } -- 2.47.3