summaryrefslogtreecommitdiffstats
path: root/test/cmsapitest.c
diff options
context:
space:
mode:
authorDaniel Fiala <daniel@openssl.org>2022-09-21 15:29:51 +0200
committerTomas Mraz <tomas@openssl.org>2022-09-23 11:14:12 +0200
commit678b489a2ae8af289cef939a538235686b448c0e (patch)
tree572d64634f7aa85fc606904e0c6bc19f9a2f72fe /test/cmsapitest.c
parent78c44b05945be07eae86f0164b9b777e2de2295b (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)
Diffstat (limited to 'test/cmsapitest.c')
-rw-r--r--test/cmsapitest.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/test/cmsapitest.c b/test/cmsapitest.c
index df54edb43d..8187fec761 100644
--- a/test/cmsapitest.c
+++ b/test/cmsapitest.c
@@ -302,18 +302,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;
@@ -321,6 +366,7 @@ static int test_d2i_CMS_bio_file_encrypted_data(void)
end:
CMS_ContentInfo_free(cms);
BIO_free(bio);
+ OPENSSL_free(buf);
return ret;
}
@@ -370,7 +416,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;
}