summaryrefslogtreecommitdiffstats
path: root/providers/implementations/encode_decode
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-10-25 13:07:01 +0100
committerPauli <pauli@openssl.org>2021-10-27 08:58:45 +1000
commit238a4c5555c89ac7f99694882f38115f3f61bf11 (patch)
tree50e737bff39053b405c225b5e75a3a28cc72f8c1 /providers/implementations/encode_decode
parentd146811f6cce155eeb1a87396943c953acb08fb6 (diff)
Don't crash encoding a public key with no public key value
If asked to encode an EC_KEY public key, but no public key value is present in the structure, we should fail rather than crash. Fixes the crash seen here: https://mta.openssl.org/pipermail/openssl-users/2021-October/014479.html Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16911) (cherry picked from commit 6187d9eac2738e873d23c0c91f9769333b1bb6af)
Diffstat (limited to 'providers/implementations/encode_decode')
-rw-r--r--providers/implementations/encode_decode/encode_key2any.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/providers/implementations/encode_decode/encode_key2any.c b/providers/implementations/encode_decode/encode_key2any.c
index f142f2b242..9ee12a9fd4 100644
--- a/providers/implementations/encode_decode/encode_key2any.c
+++ b/providers/implementations/encode_decode/encode_key2any.c
@@ -701,6 +701,10 @@ static int prepare_ec_params(const void *eckey, int nid, int save,
static int ec_spki_pub_to_der(const void *eckey, unsigned char **pder)
{
+ if (EC_KEY_get0_public_key(eckey) == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PUBLIC_KEY);
+ return 0;
+ }
return i2o_ECPublicKey(eckey, pder);
}