]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
SMIME_text() and SMIME_crlf_copy() small refactoring
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Sat, 11 Oct 2025 12:10:48 +0000 (20:10 +0800)
committerTomas Mraz <tomas@openssl.org>
Fri, 17 Oct 2025 17:32:21 +0000 (19:32 +0200)
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 <MegaManSec@users.noreply.github.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28879)

crypto/asn1/asn_mime.c

index 2c419eb6ea57dd7bb8fcc4c2bf4901b0b9411e3f..b85f734e66796cd46376ed60a7e2644936da30db 100644 (file)
@@ -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;
 }