Loading crypto/bio/bss_mem.c +1 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,7 @@ static int mem_read(BIO *b, char *out, int outl) if ((out != NULL) && (ret > 0)) { memcpy(out, bm->data, ret); bm->length -= ret; bm->max -= ret; bm->data += ret; } else if (bm->length == 0) { ret = b->num; Loading test/bio_memleak_test.c +79 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,83 @@ finish: return ok; } static int test_bio_new_mem_buf(void) { int ok = 0; BIO *bio; BUF_MEM *bufmem; char data[16]; bio = BIO_new_mem_buf("Hello World\n", 12); if (!TEST_ptr(bio)) goto finish; if (!TEST_int_eq(BIO_read(bio, data, 5), 5)) goto finish; if (!TEST_mem_eq(data, 5, "Hello", 5)) goto finish; if (!TEST_int_gt(BIO_get_mem_ptr(bio, &bufmem), 0)) goto finish; if (!TEST_int_lt(BIO_write(bio, "test", 4), 0)) goto finish; if (!TEST_int_eq(BIO_read(bio, data, 16), 7)) goto finish; if (!TEST_mem_eq(data, 7, " World\n", 7)) 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; ok = 1; finish: BIO_free(bio); return ok; } static int test_bio_rdonly_mem_buf(void) { int ok = 0; BIO *bio, *bio2 = NULL; BUF_MEM *bufmem; char data[16]; bio = BIO_new_mem_buf("Hello World\n", 12); if (!TEST_ptr(bio)) goto finish; if (!TEST_int_eq(BIO_read(bio, data, 5), 5)) goto finish; if (!TEST_mem_eq(data, 5, "Hello", 5)) goto finish; if (!TEST_int_gt(BIO_get_mem_ptr(bio, &bufmem), 0)) goto finish; (void)BIO_set_close(bio, BIO_NOCLOSE); bio2 = BIO_new(BIO_s_mem()); if (!TEST_ptr(bio2)) goto finish; BIO_set_mem_buf(bio2, bufmem, BIO_CLOSE); BIO_set_flags(bio2, BIO_FLAGS_MEM_RDONLY); if (!TEST_int_eq(BIO_read(bio2, data, 16), 7)) goto finish; if (!TEST_mem_eq(data, 7, " World\n", 7)) goto finish; if (!TEST_int_gt(BIO_reset(bio2), 0)) goto finish; if (!TEST_int_eq(BIO_read(bio2, data, 16), 7)) goto finish; if (!TEST_mem_eq(data, 7, " World\n", 7)) goto finish; ok = 1; finish: BIO_free(bio); BIO_free(bio2); return ok; } int global_init(void) { CRYPTO_set_mem_debug(1); Loading @@ -79,5 +156,7 @@ int setup_tests(void) { ADD_TEST(test_bio_memleak); ADD_TEST(test_bio_get_mem); ADD_TEST(test_bio_new_mem_buf); ADD_TEST(test_bio_rdonly_mem_buf); return 1; } Loading
crypto/bio/bss_mem.c +1 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,7 @@ static int mem_read(BIO *b, char *out, int outl) if ((out != NULL) && (ret > 0)) { memcpy(out, bm->data, ret); bm->length -= ret; bm->max -= ret; bm->data += ret; } else if (bm->length == 0) { ret = b->num; Loading
test/bio_memleak_test.c +79 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,83 @@ finish: return ok; } static int test_bio_new_mem_buf(void) { int ok = 0; BIO *bio; BUF_MEM *bufmem; char data[16]; bio = BIO_new_mem_buf("Hello World\n", 12); if (!TEST_ptr(bio)) goto finish; if (!TEST_int_eq(BIO_read(bio, data, 5), 5)) goto finish; if (!TEST_mem_eq(data, 5, "Hello", 5)) goto finish; if (!TEST_int_gt(BIO_get_mem_ptr(bio, &bufmem), 0)) goto finish; if (!TEST_int_lt(BIO_write(bio, "test", 4), 0)) goto finish; if (!TEST_int_eq(BIO_read(bio, data, 16), 7)) goto finish; if (!TEST_mem_eq(data, 7, " World\n", 7)) 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; ok = 1; finish: BIO_free(bio); return ok; } static int test_bio_rdonly_mem_buf(void) { int ok = 0; BIO *bio, *bio2 = NULL; BUF_MEM *bufmem; char data[16]; bio = BIO_new_mem_buf("Hello World\n", 12); if (!TEST_ptr(bio)) goto finish; if (!TEST_int_eq(BIO_read(bio, data, 5), 5)) goto finish; if (!TEST_mem_eq(data, 5, "Hello", 5)) goto finish; if (!TEST_int_gt(BIO_get_mem_ptr(bio, &bufmem), 0)) goto finish; (void)BIO_set_close(bio, BIO_NOCLOSE); bio2 = BIO_new(BIO_s_mem()); if (!TEST_ptr(bio2)) goto finish; BIO_set_mem_buf(bio2, bufmem, BIO_CLOSE); BIO_set_flags(bio2, BIO_FLAGS_MEM_RDONLY); if (!TEST_int_eq(BIO_read(bio2, data, 16), 7)) goto finish; if (!TEST_mem_eq(data, 7, " World\n", 7)) goto finish; if (!TEST_int_gt(BIO_reset(bio2), 0)) goto finish; if (!TEST_int_eq(BIO_read(bio2, data, 16), 7)) goto finish; if (!TEST_mem_eq(data, 7, " World\n", 7)) goto finish; ok = 1; finish: BIO_free(bio); BIO_free(bio2); return ok; } int global_init(void) { CRYPTO_set_mem_debug(1); Loading @@ -79,5 +156,7 @@ int setup_tests(void) { ADD_TEST(test_bio_memleak); ADD_TEST(test_bio_get_mem); ADD_TEST(test_bio_new_mem_buf); ADD_TEST(test_bio_rdonly_mem_buf); return 1; }