Skip to content

Commit

Permalink
Fix SMIME_crlf_copy() to properly report an error
Browse files Browse the repository at this point in the history
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 #19919)

(cherry picked from commit 6259cf3)
  • Loading branch information
mattcaswell authored and t8m committed Dec 22, 2022
1 parent 1619478 commit 0a3eeb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 5 additions & 1 deletion crypto/asn1/asn_mime.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 3 additions & 7 deletions test/bio_memleak_test.c
Expand Up @@ -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))
Expand Down

0 comments on commit 0a3eeb3

Please sign in to comment.