Fix SMIME_crlf_copy() to properly report an error
authorMatt Caswell <matt@openssl.org>
Tue, 6 Dec 2022 14:21:23 +0000 (14:21 +0000)
committerTomas Mraz <tomas@openssl.org>
Thu, 22 Dec 2022 10:07:07 +0000 (11:07 +0100)
If the BIO unexpectedly fails to flush then SMIME_crlf_copy() was not
correctly reporting the error. We modify it to properly propagate the
error condition.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19920)

crypto/asn1/asn_mime.c

index 38735cd86f3ea93c4309ef6fe5129b2245b5154a..36853612b69c16ddc687acc2d4c4afcd50eb747b 100644 (file)
@@ -489,6 +489,7 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
     char eol;
     int len;
     char linebuf[MAX_SMLEN];
+    int ret;
     /*
      * Buffer output so we don't write one line at a time. This is useful
      * when streaming as we don't end up with one OCTET STRING per line.
@@ -523,9 +524,12 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
                 BIO_write(out, "\r\n", 2);
         }
     }
-    (void)BIO_flush(out);
+    ret = BIO_flush(out);
     BIO_pop(out);
     BIO_free(bf);
+    if (ret <= 0)
+        return 0;
+
     return 1;
 }