diff options
author | Daniel Fiala <daniel@openssl.org> | 2022-09-21 15:29:51 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-09-23 11:14:59 +0200 |
commit | d40de2cc04b9a1b1adf42d9f2218a224e4d14de4 (patch) | |
tree | 6d6fbaba9ec04283091cee9d726bb97bd87b6531 /test | |
parent | 843a9a9ff6f22a4340eb10cc0ed2a5606bf4d27a (diff) |
Clear incorrectly reported errors in d2i_CMS_ContentInfo
Fixes openssl#19003
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19255)
(cherry picked from commit 678b489a2ae8af289cef939a538235686b448c0e)
Diffstat (limited to 'test')
-rw-r--r-- | test/cmsapitest.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/test/cmsapitest.c b/test/cmsapitest.c index b40089becd..a19fb0683c 100644 --- a/test/cmsapitest.c +++ b/test/cmsapitest.c @@ -289,18 +289,63 @@ static int test_d2i_CMS_bio_NULL(void) return ret; } -static int test_d2i_CMS_bio_file_encrypted_data(void) +static unsigned char *read_all(BIO *bio, long *p_len) +{ + const int step = 256; + unsigned char *buf = NULL; + unsigned char *tmp = NULL; + int ret; + + *p_len = 0; + for (;;) { + tmp = OPENSSL_realloc(buf, *p_len + step); + if (tmp == NULL) + break; + buf = tmp; + ret = BIO_read(bio, buf + *p_len, step); + if (ret < 0) + break; + + *p_len += ret; + + if (ret < step) + return buf; + } + + /* Error */ + OPENSSL_free(buf); + *p_len = 0; + return NULL; +} + +static int test_d2i_CMS_decode(const int idx) { BIO *bio = NULL; CMS_ContentInfo *cms = NULL; + unsigned char *buf = NULL; + const unsigned char *tmp = NULL; + long buf_len = 0; int ret = 0; ERR_clear_error(); - if (!TEST_ptr(bio = BIO_new_file(derin, "r")) - || !TEST_ptr(cms = d2i_CMS_bio(bio, NULL))) + if (!TEST_ptr(bio = BIO_new_file(derin, "r"))) goto end; + switch (idx) { + case 0: + if (!TEST_ptr(cms = d2i_CMS_bio(bio, NULL))) + goto end; + break; + case 1: + if (!TEST_ptr(buf = read_all(bio, &buf_len))) + goto end; + tmp = buf; + if (!TEST_ptr(cms = d2i_CMS_ContentInfo(NULL, &tmp, buf_len))) + goto end; + break; + } + if (!TEST_int_eq(ERR_peek_error(), 0)) goto end; @@ -308,6 +353,7 @@ static int test_d2i_CMS_bio_file_encrypted_data(void) end: CMS_ContentInfo_free(cms); BIO_free(bio); + OPENSSL_free(buf); return ret; } @@ -357,7 +403,7 @@ int setup_tests(void) ADD_TEST(test_encrypt_decrypt_aes_192_gcm); ADD_TEST(test_encrypt_decrypt_aes_256_gcm); ADD_TEST(test_d2i_CMS_bio_NULL); - ADD_TEST(test_d2i_CMS_bio_file_encrypted_data); + ADD_ALL_TESTS(test_d2i_CMS_decode, 2); return 1; } |