diff options
author | Tomas Mraz <tmraz@fedoraproject.org> | 2019-06-18 16:41:48 +0200 |
---|---|---|
committer | Tomas Mraz <tmraz@fedoraproject.org> | 2019-06-19 14:29:27 +0200 |
commit | 8b7b32921e63c492fa7233d81b11ee4d7ba266de (patch) | |
tree | ff5c3fcb6f67477a811d3da6fa312755037f33ba /test/bio_memleak_test.c | |
parent | a1998897f66858ec7d2d184e98f2be1e46ae2d78 (diff) | |
download | openssl-new-8b7b32921e63c492fa7233d81b11ee4d7ba266de.tar.gz |
Fix and document BIO_FLAGS_NONCLEAR_RST behavior on memory BIO
The BIO_FLAGS_NONCLEAR_RST flag behavior was not properly documented
and it also caused the length to be incorrectly set after the reset
operation.
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9179)
Diffstat (limited to 'test/bio_memleak_test.c')
-rw-r--r-- | test/bio_memleak_test.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/bio_memleak_test.c b/test/bio_memleak_test.c index fab5ce73cf..dab61f6f9a 100644 --- a/test/bio_memleak_test.c +++ b/test/bio_memleak_test.c @@ -181,6 +181,45 @@ finish: return ok; } +static int test_bio_nonclear_rst(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_NONCLEAR_RST); + + 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; + + if (!TEST_int_eq(BIO_read(bio, data, 16), 12)) + goto finish; + if (!TEST_mem_eq(data, 12, "Hello World\n", 12)) + goto finish; + + BIO_clear_flags(bio, BIO_FLAGS_NONCLEAR_RST); + if (!TEST_int_gt(BIO_reset(bio), 0)) + goto finish; + + if (!TEST_int_lt(BIO_read(bio, data, 16), 1)) + goto finish; + + ok = 1; + +finish: + BIO_free(bio); + return ok; +} int global_init(void) { @@ -196,5 +235,6 @@ int setup_tests(void) ADD_TEST(test_bio_new_mem_buf); ADD_TEST(test_bio_rdonly_mem_buf); ADD_TEST(test_bio_rdwr_rdonly); + ADD_TEST(test_bio_nonclear_rst); return 1; } |