summaryrefslogtreecommitdiffstats
path: root/test/evp_extra_test2.c
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-05-25 09:58:35 +0200
committerTomas Mraz <tomas@openssl.org>2021-05-26 13:04:38 +0200
commit05814be8d647ec3056866c13e68c4b48c788ec23 (patch)
tree44d61433de5570b08372de6e2b69570be01b368a /test/evp_extra_test2.c
parent07f65429c34cb581484371f7d45cb83815f95484 (diff)
Add negative test cases for PEM_read_bio_PrivateKey
Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15441)
Diffstat (limited to 'test/evp_extra_test2.c')
-rw-r--r--test/evp_extra_test2.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c
index 3f7edac278..e480ae9555 100644
--- a/test/evp_extra_test2.c
+++ b/test/evp_extra_test2.c
@@ -414,6 +414,41 @@ static int test_d2i_PrivateKey_ex(int testid)
return ok;
}
+static int test_PEM_read_bio_negative(int testid)
+{
+ int ok = 0;
+ OSSL_PROVIDER *provider = NULL;
+ BIO *key_bio = NULL;
+ EVP_PKEY *pkey = NULL;
+
+ if (!TEST_ptr(key_bio = BIO_new_mem_buf(keydata[testid].kder, keydata[testid].size)))
+ goto err;
+ ERR_clear_error();
+ if (!TEST_ptr_null(pkey = PEM_read_bio_PrivateKey(key_bio, NULL, NULL, NULL)))
+ goto err;
+ if (!TEST_int_ne(ERR_peek_error(), 0))
+ goto err;
+ if (!TEST_ptr(provider = OSSL_PROVIDER_load(NULL, "default")))
+ goto err;
+ if (!TEST_int_ge(BIO_seek(key_bio, 0), 0))
+ goto err;
+ ERR_clear_error();
+ if (!TEST_ptr_null(pkey = PEM_read_bio_PrivateKey(key_bio, NULL, NULL, NULL)))
+ goto err;
+ if (!TEST_int_ne(ERR_peek_error(), 0))
+ goto err;
+
+ ok = 1;
+
+ err:
+ test_openssl_errors();
+ EVP_PKEY_free(pkey);
+ BIO_free(key_bio);
+ OSSL_PROVIDER_unload(provider);
+
+ return ok;
+}
+
static int do_fromdata_key_is_equal(const OSSL_PARAM params[],
const EVP_PKEY *expected, const char *type)
{
@@ -807,6 +842,7 @@ int setup_tests(void)
#ifndef OPENSSL_NO_DES
ADD_TEST(test_pkcs8key_nid_bio);
#endif
+ ADD_ALL_TESTS(test_PEM_read_bio_negative, OSSL_NELEM(keydata));
return 1;
}