Browse code

OpenSSL: check EVP_PKEY key types before returning the pkey

The internal EVP_PKEY::pkey member is an union thus we need to check for
the real key type before we can return the corresponding RSA, DSA or EC
public key.

Reported-by: Selva Nair <selva.nair@gmail.com>
Signed-off-by: Emmanuel Deloget <logout@free.fr>

Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <e8333f0b838670e558a9fe292cea8988484cd77f.1515775195.git.logout@free.fr>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16202.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Emmanuel Deloget authored on 2018/01/13 01:48:24
Showing 1 changed files
... ...
@@ -240,7 +240,7 @@ X509_OBJECT_get_type(const X509_OBJECT *obj)
240 240
 static inline RSA *
241 241
 EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
242 242
 {
243
-    return pkey ? pkey->pkey.rsa : NULL;
243
+    return (pkey && pkey->type == EVP_PKEY_RSA) ? pkey->pkey.rsa : NULL;
244 244
 }
245 245
 #endif
246 246
 
... ...
@@ -254,7 +254,7 @@ EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
254 254
 static inline EC_KEY *
255 255
 EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
256 256
 {
257
-    return pkey ? pkey->pkey.ec : NULL;
257
+    return (pkey && pkey->type == EVP_PKEY_EC) ? pkey->pkey.ec : NULL;
258 258
 }
259 259
 #endif
260 260
 
... ...
@@ -282,7 +282,7 @@ EVP_PKEY_id(const EVP_PKEY *pkey)
282 282
 static inline DSA *
283 283
 EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
284 284
 {
285
-    return pkey ? pkey->pkey.dsa : NULL;
285
+    return (pkey && pkey->type == EVP_PKEY_DSA) ? pkey->pkey.dsa : NULL;
286 286
 }
287 287
 #endif
288 288