Skip to content

Commit

Permalink
Add test for the BIO_s_mem rdwr->rdonly->rdwr use-case
Browse files Browse the repository at this point in the history
Reviewed-by: Bernd Edlinger <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
(Merged from openssl#8649)
  • Loading branch information
t8m authored and mattcaswell committed Apr 16, 2019
1 parent 3d42833 commit 06add28
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/bio_memleak_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,43 @@ static int test_bio_rdonly_mem_buf(void)
return ok;
}

static int test_bio_rdwr_rdonly(void)
{
int ok = 0;
BIO *bio = NULL;
char data[16];

bio = BIO_new(BIO_s_mem());
if (!TEST_ptr(bio))
goto finish;
if (!TEST_int_eq(BIO_puts(bio, "Hello World\n"), 12))
goto finish;

BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY);
if (!TEST_int_eq(BIO_read(bio, data, 16), 12))
goto finish;
if (!TEST_mem_eq(data, 12, "Hello World\n", 12))
goto finish;
if (!TEST_int_gt(BIO_reset(bio), 0))
goto finish;

BIO_clear_flags(bio, BIO_FLAGS_MEM_RDONLY);
if (!TEST_int_eq(BIO_puts(bio, "Hi!\n"), 4))
goto finish;
if (!TEST_int_eq(BIO_read(bio, data, 16), 16))
goto finish;

if (!TEST_mem_eq(data, 16, "Hello World\nHi!\n", 16))
goto finish;

ok = 1;

finish:
BIO_free(bio);
return ok;
}


int global_init(void)
{
CRYPTO_set_mem_debug(1);
Expand All @@ -158,5 +195,6 @@ int setup_tests(void)
ADD_TEST(test_bio_get_mem);
ADD_TEST(test_bio_new_mem_buf);
ADD_TEST(test_bio_rdonly_mem_buf);
ADD_TEST(test_bio_rdwr_rdonly);
return 1;
}

0 comments on commit 06add28

Please sign in to comment.