RT3754: check for NULL pointer
authorEmilia Kasper <emilia@openssl.org>
Tue, 1 Sep 2015 14:31:55 +0000 (16:31 +0200)
committerEmilia Kasper <emilia@openssl.org>
Thu, 10 Sep 2015 15:23:02 +0000 (17:23 +0200)
Fix both the caller to error out on malloc failure, as well as the
eventual callee to handle a NULL gracefully.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
crypto/evp/p_lib.c
crypto/evp/pmeth_gn.c

index 1171d3086d0b2d373c01258b5fb473caa25318ec..c0171244d5d0109ede5aaffb7a88cba1ac75ffb8 100644 (file)
@@ -253,7 +253,7 @@ int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len)
 
 int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)
 {
-    if (!EVP_PKEY_set_type(pkey, type))
+    if (pkey == NULL || !EVP_PKEY_set_type(pkey, type))
         return 0;
     pkey->pkey.ptr = key;
     return (key != NULL);
index 59f81342e94d0b6042e35551976da9862f67b95d..6435f1b632cfe804c22057f985c73edbe2118c1e 100644 (file)
@@ -96,12 +96,17 @@ int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
         return -1;
     }
 
-    if (!ppkey)
+    if (ppkey == NULL)
         return -1;
 
-    if (!*ppkey)
+    if (*ppkey == NULL)
         *ppkey = EVP_PKEY_new();
 
+    if (*ppkey == NULL) {
+        EVPerr(EVP_F_EVP_PKEY_PARAMGEN, ERR_R_MALLOC_FAILURE);
+        return -1;
+    }
+
     ret = ctx->pmeth->paramgen(ctx, *ppkey);
     if (ret <= 0) {
         EVP_PKEY_free(*ppkey);