Don't crash encoding a public key with no public key value
[openssl.git] / providers / implementations / encode_decode / encode_key2any.c
index f142f2b2424d936fa481463a38675bd316070551..9ee12a9fd488174afe025b878ce1d4b3b20c0d94 100644 (file)
@@ -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);
 }