diff --git a/crypto/pkcs7/bio/bio_deprecated_test.cc b/crypto/pkcs7/bio/bio_deprecated_test.cc index 008d2eba5b0..69752ce7940 100644 --- a/crypto/pkcs7/bio/bio_deprecated_test.cc +++ b/crypto/pkcs7/bio/bio_deprecated_test.cc @@ -54,8 +54,10 @@ TEST_P(BIODeprecatedTest, MessageDigestBasic) { const EVP_MD *md = GetParam().md(); ASSERT_TRUE(md); + // Simple initialization and error cases bio_md.reset(BIO_new(BIO_f_md())); ASSERT_TRUE(bio_md); + EXPECT_FALSE(BIO_reset(bio_md.get())); EXPECT_TRUE(BIO_set_md(bio_md.get(), (EVP_MD *)md)); EVP_MD_CTX *ctx_tmp; // |bio_md| owns the context, we just take a ref here EXPECT_TRUE(BIO_get_md_ctx(bio_md.get(), &ctx_tmp)); @@ -67,6 +69,11 @@ TEST_P(BIODeprecatedTest, MessageDigestBasic) { EXPECT_FALSE(BIO_ctrl(bio_md.get(), BIO_CTRL_DUP, 0, nullptr)); EXPECT_FALSE(BIO_ctrl(bio_md.get(), BIO_CTRL_GET_CALLBACK, 0, nullptr)); EXPECT_FALSE(BIO_ctrl(bio_md.get(), BIO_CTRL_SET_CALLBACK, 0, nullptr)); + EXPECT_FALSE(BIO_read(bio_md.get(), buf, 0)); + EXPECT_FALSE(BIO_write(bio_md.get(), buf, 0)); + EXPECT_EQ(0UL, BIO_number_read(bio_md.get())); + EXPECT_EQ(0UL, BIO_number_written(bio_md.get())); + EXPECT_FALSE(BIO_gets(bio_md.get(), (char *)buf, EVP_MD_size(md) - 1)); // Write-through digest BIO bio_md.reset(BIO_new(BIO_f_md())); @@ -146,9 +153,9 @@ TEST_P(BIODeprecatedTest, MessageDigestRandomized) { const size_t block_size = EVP_MD_block_size(md); std::vector> io_patterns = { + {}, {0}, {1}, - {}, {8, 8, 8, 8}, {block_size - 1, 1, block_size + 1, block_size, block_size - 1}, {4, 1, 5, 3, 2, 0, 1, sizeof(message_buf), 133, 4555, 22, 4, 7964, 1234}, @@ -209,6 +216,7 @@ TEST_P(BIODeprecatedTest, MessageDigestRandomized) { int rsize = BIO_read(bio.get(), message_buf, io_size); EXPECT_EQ((int)io_size, rsize); } + EXPECT_TRUE(BIO_eof(bio.get())); digest_size = BIO_gets(bio_md.get(), (char *)digest_buf, sizeof(digest_buf)); ASSERT_EQ(EVP_MD_CTX_size(ctx.get()), digest_size); diff --git a/crypto/pkcs7/bio/md.c b/crypto/pkcs7/bio/md.c index 263ebfc72c0..5a21b8cdf7b 100644 --- a/crypto/pkcs7/bio/md.c +++ b/crypto/pkcs7/bio/md.c @@ -33,7 +33,6 @@ static int md_new(BIO *b) { return 0; } - BIO_set_init(b, 1); BIO_set_data(b, ctx); return 1; @@ -131,7 +130,6 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr) { case BIO_C_GET_MD_CTX: pctx = ptr; *pctx = ctx; - BIO_set_init(b, 1); break; case BIO_C_SET_MD: md = ptr;