From: Joshua Rogers Date: Sat, 11 Oct 2025 12:10:48 +0000 (+0800) Subject: SMIME_text() and SMIME_crlf_copy() small refactoring X-Git-Tag: 4.0-PRE-CLANG-FORMAT-WEBKIT~327 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=999bce720fcefb0109368f942d5170c1c98dd5a6;p=thirdparty%2Fopenssl.git SMIME_text() and SMIME_crlf_copy() small refactoring 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) --- 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; }