Skip to content

Commit

Permalink
Cover basic error cases, no init on new/get
Browse files Browse the repository at this point in the history
  • Loading branch information
WillChilds-Klein committed Sep 30, 2024
1 parent df434b2 commit bc6f15f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 9 additions & 1 deletion crypto/pkcs7/bio/bio_deprecated_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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()));
Expand Down Expand Up @@ -146,9 +153,9 @@ TEST_P(BIODeprecatedTest, MessageDigestRandomized) {

const size_t block_size = EVP_MD_block_size(md);
std::vector<std::vector<size_t>> 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},
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions crypto/pkcs7/bio/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ static int md_new(BIO *b) {
return 0;
}

BIO_set_init(b, 1);
BIO_set_data(b, ctx);

return 1;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bc6f15f

Please sign in to comment.