diff options
author | 2019-10-31 12:46:02 +0000 | |
---|---|---|
committer | 2019-10-31 12:46:02 +0000 | |
commit | 5bc73cc3255e1ee29a1e0dc2a7c6ac858d503ec3 (patch) | |
tree | 60e61f202c464bd276dbf820d5670aefafd4aaec /lib/libcrypto/rsa/rsa_pmeth.c | |
parent | Avoid potentially leaking pub_exp in pkey_rsa_copy(). (diff) | |
download | wireguard-openbsd-5bc73cc3255e1ee29a1e0dc2a7c6ac858d503ec3.tar.xz wireguard-openbsd-5bc73cc3255e1ee29a1e0dc2a7c6ac858d503ec3.zip |
Clean up some code.
Assign and test, explicitly test against NULL and use calloc() rather than
malloc.
ok inoguchi@
Diffstat (limited to 'lib/libcrypto/rsa/rsa_pmeth.c')
-rw-r--r-- | lib/libcrypto/rsa/rsa_pmeth.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/libcrypto/rsa/rsa_pmeth.c b/lib/libcrypto/rsa/rsa_pmeth.c index fd567658c21..4132d066399 100644 --- a/lib/libcrypto/rsa/rsa_pmeth.c +++ b/lib/libcrypto/rsa/rsa_pmeth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_pmeth.c,v 1.25 2019/10/31 12:32:48 jsing Exp $ */ +/* $OpenBSD: rsa_pmeth.c,v 1.26 2019/10/31 12:46:02 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -149,11 +149,12 @@ pkey_rsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk) { - if (ctx->tbuf) + if (ctx->tbuf != NULL) return 1; - ctx->tbuf = malloc(EVP_PKEY_size(pk->pkey)); - if (!ctx->tbuf) + if ((ctx->tbuf = calloc(1, EVP_PKEY_size(pk->pkey))) == NULL) { + RSAerror(ERR_R_MALLOC_FAILURE); return 0; + } return 1; } @@ -635,19 +636,20 @@ pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) BN_GENCB *pcb, cb; int ret; - if (!rctx->pub_exp) { - rctx->pub_exp = BN_new(); - if (!rctx->pub_exp || !BN_set_word(rctx->pub_exp, RSA_F4)) + if (rctx->pub_exp == NULL) { + if ((rctx->pub_exp = BN_new()) == NULL) + return 0; + if (!BN_set_word(rctx->pub_exp, RSA_F4)) return 0; } - rsa = RSA_new(); - if (!rsa) + if ((rsa = RSA_new()) == NULL) return 0; - if (ctx->pkey_gencb) { + if (ctx->pkey_gencb != NULL) { pcb = &cb; evp_pkey_set_cb_translate(pcb, ctx); - } else + } else { pcb = NULL; + } ret = RSA_generate_key_ex(rsa, rctx->nbits, rctx->pub_exp, pcb); if (ret > 0) EVP_PKEY_assign_RSA(pkey, rsa); |