Fix CID 1466714 : Null pointer dereference in EVP_PKEY_CTX_ctrl() due to new call...
authorShane Lontis <shane.lontis@oracle.com>
Mon, 21 Sep 2020 00:59:20 +0000 (10:59 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Wed, 23 Sep 2020 07:16:38 +0000 (17:16 +1000)
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12930)

crypto/evp/pmeth_lib.c

index 0d719943f07cacec43dc094cf3e96ca1e1acbb83..26193cd6440f700e9bd2f35238afce67162ffb3a 100644 (file)
@@ -1450,11 +1450,6 @@ static int evp_pkey_ctx_ctrl_int(EVP_PKEY_CTX *ctx, int keytype, int optype,
 {
     int ret = 0;
 
-    if (ctx == NULL) {
-        EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
-        return -2;
-    }
-
     /*
      * If the method has a |digest_custom| function, we can relax the
      * operation type check, since this can be called before the operation
@@ -1498,6 +1493,10 @@ int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
 {
     int ret = 0;
 
+    if (ctx == NULL) {
+        EVPerr(0, EVP_R_COMMAND_NOT_SUPPORTED);
+        return -2;
+    }
     /* If unsupported, we don't want that reported here */
     ERR_set_mark();
     ret = evp_pkey_ctx_store_cached_data(ctx, keytype, optype,
@@ -1514,7 +1513,6 @@ int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
         if (ret < 1 || ctx->operation == EVP_PKEY_OP_UNDEFINED)
             return ret;
     }
-
     return evp_pkey_ctx_ctrl_int(ctx, keytype, optype, cmd, p1, p2);
 }