test/evp_extra_test.c: fix null pointer dereference
It's actually not a real issue but caused by the absence of the default case
which does not occur in reality but which makes coverity see a code path where
pkey remains unassigned.
Reported by Coverity Scan (CID 1423323)
[extended tests]
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7158)
Dr. Matthias St. Pierre authored 5 years ago
Matt Caswell committed 5 years ago
854 | 854 | |
855 | 855 | p = input; |
856 | 856 | |
857 | if (type == 0 && | |
858 | (!TEST_ptr(pkey = d2i_AutoPrivateKey(NULL, &p, input_len)) | |
859 | || !TEST_ptr_eq(p, input + input_len) | |
860 | || !TEST_int_eq(EVP_PKEY_id(pkey), expected_id))) | |
861 | goto done; | |
862 | ||
857 | switch (type) { | |
858 | case 0: | |
859 | if (!TEST_ptr(pkey = d2i_AutoPrivateKey(NULL, &p, input_len)) | |
860 | || !TEST_ptr_eq(p, input + input_len) | |
861 | || !TEST_int_eq(EVP_PKEY_id(pkey), expected_id)) | |
862 | goto done; | |
863 | break; | |
863 | 864 | #ifndef OPENSSL_NO_EC |
864 | if (type == 1 && | |
865 | (!TEST_ptr(pubkey = BIO_new_mem_buf(input, input_len)) | |
866 | || !TEST_ptr(eckey = d2i_EC_PUBKEY_bio(pubkey, NULL)) | |
867 | || !TEST_ptr(pkey = EVP_PKEY_new()) | |
868 | || !TEST_true(EVP_PKEY_assign_EC_KEY(pkey, eckey)))) | |
869 | goto done; | |
870 | ||
871 | if (type == 2 && | |
872 | (!TEST_ptr(eckey = d2i_ECParameters(NULL, &p, input_len)) | |
873 | || !TEST_ptr_eq(p, input + input_len) | |
874 | || !TEST_ptr(pkey = EVP_PKEY_new()) | |
875 | || !TEST_true(EVP_PKEY_assign_EC_KEY(pkey, eckey)))) | |
876 | goto done; | |
865 | case 1: | |
866 | if (!TEST_ptr(pubkey = BIO_new_mem_buf(input, input_len)) | |
867 | || !TEST_ptr(eckey = d2i_EC_PUBKEY_bio(pubkey, NULL)) | |
868 | || !TEST_ptr(pkey = EVP_PKEY_new()) | |
869 | || !TEST_true(EVP_PKEY_assign_EC_KEY(pkey, eckey))) | |
870 | goto done; | |
871 | break; | |
872 | case 2: | |
873 | if (!TEST_ptr(eckey = d2i_ECParameters(NULL, &p, input_len)) | |
874 | || !TEST_ptr_eq(p, input + input_len) | |
875 | || !TEST_ptr(pkey = EVP_PKEY_new()) | |
876 | || !TEST_true(EVP_PKEY_assign_EC_KEY(pkey, eckey))) | |
877 | goto done; | |
878 | break; | |
877 | 879 | #endif |
880 | default: | |
881 | return 0; | |
882 | } | |
878 | 883 | |
879 | 884 | if (!TEST_ptr(ctx = EVP_PKEY_CTX_new(pkey, NULL))) |
880 | 885 | goto done; |