Skip to content

Commit

Permalink
EVP: when setting the operation to EVP_PKEY_OP_UNDEFINED, clean up!
Browse files Browse the repository at this point in the history
There were a few instances where we set the EVP_PKEY_CTX operation to
EVP_PKEY_OP_UNDEFINED, but forgot to clean up first.  After the
operation is made undefined, there's no way to know what should be
cleaned away, so that must be done first, in all spots.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from openssl#11750)
  • Loading branch information
levitte committed May 8, 2020
1 parent 73d6b4e commit c7fa929
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions crypto/evp/exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx)

return ret ? 1 : 0;
err:
evp_pkey_ctx_free_old_ops(ctx);
ctx->operation = EVP_PKEY_OP_UNDEFINED;
return 0;

Expand Down
9 changes: 4 additions & 5 deletions crypto/evp/pmeth_fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation)
goto err;
}

if (ret <= 0) {
cipher->freectx(ctx->op.ciph.ciphprovctx);
ctx->op.ciph.ciphprovctx = NULL;
if (ret <= 0)
goto err;
}
return 1;

legacy:
Expand Down Expand Up @@ -162,8 +159,10 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation)
}

err:
if (ret <= 0)
if (ret <= 0) {
evp_pkey_ctx_free_old_ops(ctx);
ctx->operation = EVP_PKEY_OP_UNDEFINED;
}
return ret;
}

Expand Down
4 changes: 3 additions & 1 deletion crypto/evp/pmeth_gn.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ static int gen_init(EVP_PKEY_CTX *ctx, int operation)
#endif

end:
if (ret <= 0 && ctx != NULL)
if (ret <= 0 && ctx != NULL) {
evp_pkey_ctx_free_old_ops(ctx);
ctx->operation = EVP_PKEY_OP_UNDEFINED;
}
return ret;

not_supported:
Expand Down
1 change: 1 addition & 0 deletions crypto/evp/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation)
return ret;

err:
evp_pkey_ctx_free_old_ops(ctx);
ctx->operation = EVP_PKEY_OP_UNDEFINED;
return ret;
}
Expand Down

0 comments on commit c7fa929

Please sign in to comment.