]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
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:01:06 +0000 (11:01 +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/19918)

crypto/asn1/asn_mime.c
test/bio_memleak_test.c

index 014e482e6665aa097b7bdd1338e26393e8846a45..a26eac17313d3e6746fc5396ed24f5c55b2a98a1 100644 (file)
@@ -515,6 +515,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.
@@ -552,9 +553,12 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
             }
         }
     }
-    (void)BIO_flush(out);
+    ret = BIO_flush(out);
     BIO_pop(out);
     BIO_free(bf);
+    if (ret <= 0)
+        return 0;
+
     return 1;
 }
 
index e95c21768cc97d03471cb95c7e6233b0599079de..d9c744ff49cc55ebe64e4d30e994ad2226e5b8c6 100644 (file)
@@ -261,13 +261,9 @@ static int test_bio_i2d_ASN1_mime(void)
 
     error_callback_fired = 0;
 
-    /*
-     * The call succeeds even if the input stream ends unexpectedly as
-     * there is no handling for this case in SMIME_crlf_copy().
-     */
-    if (!TEST_true(i2d_ASN1_bio_stream(out, (ASN1_VALUE*) p7, bio,
-                                       SMIME_STREAM | SMIME_BINARY,
-                                       ASN1_ITEM_rptr(PKCS7))))
+    if (!TEST_false(i2d_ASN1_bio_stream(out, (ASN1_VALUE*) p7, bio,
+                                        SMIME_STREAM | SMIME_BINARY,
+                                        ASN1_ITEM_rptr(PKCS7))))
         goto finish;
 
     if (!TEST_int_eq(error_callback_fired, 1))