diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2019-03-01 01:55:38 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2019-04-16 10:55:36 +0100 |
commit | 27a11cd60270091f38e432aca5d46744ee66503d (patch) | |
tree | 921898d29fc8b8b3dc74f68be2a903f92fa24045 /test | |
parent | 43bb4dec99f4bed1ec20836c79967ea790594fce (diff) |
Add test for the BIO_get_mem_ptr() regression
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8649)
(cherry picked from commit c9dc22bc3d7f2df670dff66f04935e540e1b931a)
Diffstat (limited to 'test')
-rw-r--r-- | test/bio_memleak_test.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/test/bio_memleak_test.c b/test/bio_memleak_test.c index 21b46cbbd3..838cd35eb1 100644 --- a/test/bio_memleak_test.c +++ b/test/bio_memleak_test.c @@ -18,25 +18,53 @@ static int test_bio_memleak(void) int ok = 0; BIO *bio; BUF_MEM bufmem; - const char *str = "BIO test\n"; + static const char str[] = "BIO test\n"; char buf[100]; bio = BIO_new(BIO_s_mem()); - if (bio == NULL) + if (!TEST_ptr(bio)) goto finish; - bufmem.length = strlen(str) + 1; + bufmem.length = sizeof(str); bufmem.data = (char *) str; bufmem.max = bufmem.length; BIO_set_mem_buf(bio, &bufmem, BIO_NOCLOSE); BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY); + if (!TEST_int_eq(BIO_read(bio, buf, sizeof(buf)), sizeof(str))) + goto finish; + if (!TEST_mem_eq(buf, sizeof(str), str, sizeof(str))) + goto finish; + ok = 1; + +finish: + BIO_free(bio); + return ok; +} - if (BIO_read(bio, buf, sizeof(buf)) <= 0) - goto finish; +static int test_bio_get_mem(void) +{ + int ok = 0; + BIO *bio = NULL; + BUF_MEM *bufmem = NULL; - ok = strcmp(buf, str) == 0; + 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_get_mem_ptr(bio, &bufmem); + if (!TEST_ptr(bufmem)) + goto finish; + if (!TEST_int_gt(BIO_set_close(bio, BIO_NOCLOSE), 0)) + goto finish; + BIO_free(bio); + bio = NULL; + if (!TEST_mem_eq(bufmem->data, bufmem->length, "Hello World\n", 12)) + goto finish; + ok = 1; finish: BIO_free(bio); + BUF_MEM_free(bufmem); return ok; } @@ -50,5 +78,6 @@ int global_init(void) int setup_tests(void) { ADD_TEST(test_bio_memleak); + ADD_TEST(test_bio_get_mem); return 1; } |