summaryrefslogtreecommitdiff
path: root/lib/libcrypto
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-04-14 07:09:22 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-04-14 07:09:22 +0000
commit364b319f72ecb5c2f1e58716cf073863162c78a8 (patch)
treee0e394a7d929b9512916d0dd247c4548f2dbc111 /lib/libcrypto
parentbd42a3afb2194d71f6df46c3bf36231d249dc9d6 (diff)
make ENGINE_finish() succeed on NULL and simplify callers as in
OpenSSL commit 7c96dbcdab9 by Rich Salz. This cleans up the caller side quite a bit and reduces the number of lines enclosed in #ifndef OPENSSL_NO_ENGINE. codesearch.debian.net shows that almost nothing checks the return value of ENGINE_finish(). While there, replace a few nearby 'if (!ptr)' with 'if (ptr == NULL)'. ok jsing, tested by & ok inoguchi
Diffstat (limited to 'lib/libcrypto')
-rw-r--r--lib/libcrypto/asn1/d2i_pr.c8
-rw-r--r--lib/libcrypto/dh/dh_lib.c16
-rw-r--r--lib/libcrypto/dsa/dsa_lib.c16
-rw-r--r--lib/libcrypto/ecdh/ech_lib.c13
-rw-r--r--lib/libcrypto/ecdsa/ecs_lib.c13
-rw-r--r--lib/libcrypto/engine/eng_init.c8
-rw-r--r--lib/libcrypto/evp/digest.c16
-rw-r--r--lib/libcrypto/evp/evp_enc.c7
-rw-r--r--lib/libcrypto/evp/p_lib.c20
-rw-r--r--lib/libcrypto/evp/pmeth_lib.c12
-rw-r--r--lib/libcrypto/pem/pem_lib.c5
-rw-r--r--lib/libcrypto/rsa/rsa_lib.c19
12 files changed, 56 insertions, 97 deletions
diff --git a/lib/libcrypto/asn1/d2i_pr.c b/lib/libcrypto/asn1/d2i_pr.c
index 7a5880a8cd8..a657a1f3cd1 100644
--- a/lib/libcrypto/asn1/d2i_pr.c
+++ b/lib/libcrypto/asn1/d2i_pr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: d2i_pr.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: d2i_pr.c,v 1.16 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -86,10 +86,8 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
} else {
ret = *a;
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine) {
- ENGINE_finish(ret->engine);
- ret->engine = NULL;
- }
+ ENGINE_finish(ret->engine);
+ ret->engine = NULL;
#endif
}
diff --git a/lib/libcrypto/dh/dh_lib.c b/lib/libcrypto/dh/dh_lib.c
index e02ce7455a2..8a7f9386c7e 100644
--- a/lib/libcrypto/dh/dh_lib.c
+++ b/lib/libcrypto/dh/dh_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dh_lib.c,v 1.30 2018/02/22 16:41:04 jsing Exp $ */
+/* $OpenBSD: dh_lib.c,v 1.31 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -98,10 +98,8 @@ DH_set_method(DH *dh, const DH_METHOD *meth)
if (mtmp->finish)
mtmp->finish(dh);
#ifndef OPENSSL_NO_ENGINE
- if (dh->engine) {
- ENGINE_finish(dh->engine);
- dh->engine = NULL;
- }
+ ENGINE_finish(dh->engine);
+ dh->engine = NULL;
#endif
dh->meth = meth;
if (meth->init)
@@ -139,7 +137,7 @@ DH_new_method(ENGINE *engine)
ret->engine = ENGINE_get_default_DH();
if(ret->engine) {
ret->meth = ENGINE_get_DH(ret->engine);
- if (!ret->meth) {
+ if (ret->meth == NULL) {
DHerror(ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
free(ret);
@@ -166,8 +164,7 @@ DH_new_method(ENGINE *engine)
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
if (ret->meth->init != NULL && !ret->meth->init(ret)) {
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine)
- ENGINE_finish(ret->engine);
+ ENGINE_finish(ret->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
free(ret);
@@ -190,8 +187,7 @@ DH_free(DH *r)
if (r->meth->finish)
r->meth->finish(r);
#ifndef OPENSSL_NO_ENGINE
- if (r->engine)
- ENGINE_finish(r->engine);
+ ENGINE_finish(r->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data);
diff --git a/lib/libcrypto/dsa/dsa_lib.c b/lib/libcrypto/dsa/dsa_lib.c
index 8190d073486..d5fdd6e78e4 100644
--- a/lib/libcrypto/dsa/dsa_lib.c
+++ b/lib/libcrypto/dsa/dsa_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsa_lib.c,v 1.28 2018/02/20 17:52:27 tb Exp $ */
+/* $OpenBSD: dsa_lib.c,v 1.29 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -108,10 +108,8 @@ DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
if (mtmp->finish)
mtmp->finish(dsa);
#ifndef OPENSSL_NO_ENGINE
- if (dsa->engine) {
- ENGINE_finish(dsa->engine);
- dsa->engine = NULL;
- }
+ ENGINE_finish(dsa->engine);
+ dsa->engine = NULL;
#endif
dsa->meth = meth;
if (meth->init)
@@ -142,7 +140,7 @@ DSA_new_method(ENGINE *engine)
ret->engine = ENGINE_get_default_DSA();
if (ret->engine) {
ret->meth = ENGINE_get_DSA(ret->engine);
- if (!ret->meth) {
+ if (ret->meth == NULL) {
DSAerror(ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
free(ret);
@@ -170,8 +168,7 @@ DSA_new_method(ENGINE *engine)
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
if (ret->meth->init != NULL && !ret->meth->init(ret)) {
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine)
- ENGINE_finish(ret->engine);
+ ENGINE_finish(ret->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
free(ret);
@@ -196,8 +193,7 @@ DSA_free(DSA *r)
if (r->meth->finish)
r->meth->finish(r);
#ifndef OPENSSL_NO_ENGINE
- if (r->engine)
- ENGINE_finish(r->engine);
+ ENGINE_finish(r->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
diff --git a/lib/libcrypto/ecdh/ech_lib.c b/lib/libcrypto/ecdh/ech_lib.c
index 2846a88612e..cc8edafa077 100644
--- a/lib/libcrypto/ecdh/ech_lib.c
+++ b/lib/libcrypto/ecdh/ech_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ech_lib.c,v 1.13 2017/05/02 03:59:44 deraadt Exp $ */
+/* $OpenBSD: ech_lib.c,v 1.14 2018/04/14 07:09:21 tb Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
@@ -109,10 +109,8 @@ ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth)
return 0;
#ifndef OPENSSL_NO_ENGINE
- if (ecdh->engine) {
- ENGINE_finish(ecdh->engine);
- ecdh->engine = NULL;
- }
+ ENGINE_finish(ecdh->engine);
+ ecdh->engine = NULL;
#endif
ecdh->meth = meth;
return 1;
@@ -138,7 +136,7 @@ ECDH_DATA_new_method(ENGINE *engine)
ret->engine = ENGINE_get_default_ECDH();
if (ret->engine) {
ret->meth = ENGINE_get_ECDH(ret->engine);
- if (!ret->meth) {
+ if (ret->meth == NULL) {
ECDHerror(ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
free(ret);
@@ -176,8 +174,7 @@ ecdh_data_free(void *data)
ECDH_DATA *r = (ECDH_DATA *)data;
#ifndef OPENSSL_NO_ENGINE
- if (r->engine)
- ENGINE_finish(r->engine);
+ ENGINE_finish(r->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data);
diff --git a/lib/libcrypto/ecdsa/ecs_lib.c b/lib/libcrypto/ecdsa/ecs_lib.c
index 4fbe1e060b1..c688a95f3b2 100644
--- a/lib/libcrypto/ecdsa/ecs_lib.c
+++ b/lib/libcrypto/ecdsa/ecs_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ecs_lib.c,v 1.12 2017/05/02 03:59:44 deraadt Exp $ */
+/* $OpenBSD: ecs_lib.c,v 1.13 2018/04/14 07:09:21 tb Exp $ */
/* ====================================================================
* Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
*
@@ -96,10 +96,8 @@ ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth)
return 0;
#ifndef OPENSSL_NO_ENGINE
- if (ecdsa->engine) {
- ENGINE_finish(ecdsa->engine);
- ecdsa->engine = NULL;
- }
+ ENGINE_finish(ecdsa->engine);
+ ecdsa->engine = NULL;
#endif
ecdsa->meth = meth;
@@ -126,7 +124,7 @@ ECDSA_DATA_new_method(ENGINE *engine)
ret->engine = ENGINE_get_default_ECDSA();
if (ret->engine) {
ret->meth = ENGINE_get_ECDSA(ret->engine);
- if (!ret->meth) {
+ if (ret->meth == NULL) {
ECDSAerror(ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
free(ret);
@@ -164,8 +162,7 @@ ecdsa_data_free(void *data)
ECDSA_DATA *r = (ECDSA_DATA *)data;
#ifndef OPENSSL_NO_ENGINE
- if (r->engine)
- ENGINE_finish(r->engine);
+ ENGINE_finish(r->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data);
diff --git a/lib/libcrypto/engine/eng_init.c b/lib/libcrypto/engine/eng_init.c
index 75d6698c707..793adba8bea 100644
--- a/lib/libcrypto/engine/eng_init.c
+++ b/lib/libcrypto/engine/eng_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eng_init.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
+/* $OpenBSD: eng_init.c,v 1.9 2018/04/14 07:09:21 tb Exp $ */
/* ====================================================================
* Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
*
@@ -134,10 +134,8 @@ ENGINE_finish(ENGINE *e)
{
int to_return = 1;
- if (e == NULL) {
- ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
+ if (e == NULL)
+ return 1;
CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
to_return = engine_unlocked_finish(e, 1);
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
diff --git a/lib/libcrypto/evp/digest.c b/lib/libcrypto/evp/digest.c
index b69a928ab82..6a7d86d702a 100644
--- a/lib/libcrypto/evp/digest.c
+++ b/lib/libcrypto/evp/digest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: digest.c,v 1.29 2018/02/17 14:55:31 jsing Exp $ */
+/* $OpenBSD: digest.c,v 1.30 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -146,9 +146,8 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
/* Ensure an ENGINE left lying around from last time is cleared
* (the previous check attempted to avoid this if the same
* ENGINE and EVP_MD could be used). */
- if (ctx->engine)
- ENGINE_finish(ctx->engine);
- if (impl) {
+ ENGINE_finish(ctx->engine);
+ if (impl != NULL) {
if (!ENGINE_init(impl)) {
EVPerror(EVP_R_INITIALIZATION_ERROR);
return 0;
@@ -156,10 +155,10 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
} else
/* Ask if an ENGINE is reserved for this job */
impl = ENGINE_get_digest_engine(type->type);
- if (impl) {
+ if (impl != NULL) {
/* There's an ENGINE for this job ... (apparently) */
const EVP_MD *d = ENGINE_get_digest(impl, type->type);
- if (!d) {
+ if (d == NULL) {
/* Same comment from evp_enc.c */
EVPerror(EVP_R_INITIALIZATION_ERROR);
ENGINE_finish(impl);
@@ -384,10 +383,7 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
freezero(ctx->md_data, ctx->digest->ctx_size);
EVP_PKEY_CTX_free(ctx->pctx);
#ifndef OPENSSL_NO_ENGINE
- if (ctx->engine)
- /* The EVP_MD we used belongs to an ENGINE, release the
- * functional reference we held for this reason. */
- ENGINE_finish(ctx->engine);
+ ENGINE_finish(ctx->engine);
#endif
memset(ctx, 0, sizeof(*ctx));
diff --git a/lib/libcrypto/evp/evp_enc.c b/lib/libcrypto/evp/evp_enc.c
index de7c690ca79..db2deb69050 100644
--- a/lib/libcrypto/evp/evp_enc.c
+++ b/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: evp_enc.c,v 1.38 2018/02/17 16:54:08 jsing Exp $ */
+/* $OpenBSD: evp_enc.c,v 1.39 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -577,10 +577,7 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
}
free(c->cipher_data);
#ifndef OPENSSL_NO_ENGINE
- if (c->engine)
- /* The EVP_CIPHER we used belongs to an ENGINE, release the
- * functional reference we held for this reason. */
- ENGINE_finish(c->engine);
+ ENGINE_finish(c->engine);
#endif
explicit_bzero(c, sizeof(EVP_CIPHER_CTX));
return 1;
diff --git a/lib/libcrypto/evp/p_lib.c b/lib/libcrypto/evp/p_lib.c
index 811fe0c86d6..b14c95f14df 100644
--- a/lib/libcrypto/evp/p_lib.c
+++ b/lib/libcrypto/evp/p_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: p_lib.c,v 1.20 2018/02/20 18:05:28 tb Exp $ */
+/* $OpenBSD: p_lib.c,v 1.21 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -229,11 +229,8 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
if ((type == pkey->save_type) && pkey->ameth)
return 1;
#ifndef OPENSSL_NO_ENGINE
- /* If we have an ENGINE release it */
- if (pkey->engine) {
- ENGINE_finish(pkey->engine);
- pkey->engine = NULL;
- }
+ ENGINE_finish(pkey->engine);
+ pkey->engine = NULL;
#endif
}
if (str)
@@ -241,7 +238,7 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
else
ameth = EVP_PKEY_asn1_find(&e, type);
#ifndef OPENSSL_NO_ENGINE
- if (!pkey && e)
+ if (pkey == NULL)
ENGINE_finish(e);
#endif
if (!ameth) {
@@ -426,8 +423,7 @@ EVP_PKEY_type(int type)
else
ret = NID_undef;
#ifndef OPENSSL_NO_ENGINE
- if (e)
- ENGINE_finish(e);
+ ENGINE_finish(e);
#endif
return ret;
}
@@ -470,10 +466,8 @@ EVP_PKEY_free_it(EVP_PKEY *x)
x->pkey.ptr = NULL;
}
#ifndef OPENSSL_NO_ENGINE
- if (x->engine) {
- ENGINE_finish(x->engine);
- x->engine = NULL;
- }
+ ENGINE_finish(x->engine);
+ x->engine = NULL;
#endif
}
diff --git a/lib/libcrypto/evp/pmeth_lib.c b/lib/libcrypto/evp/pmeth_lib.c
index fc5f4ef91e5..6b86a0ecfb0 100644
--- a/lib/libcrypto/evp/pmeth_lib.c
+++ b/lib/libcrypto/evp/pmeth_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmeth_lib.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
+/* $OpenBSD: pmeth_lib.c,v 1.14 2018/04/14 07:09:21 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -188,10 +188,9 @@ int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
}
ret = malloc(sizeof(EVP_PKEY_CTX));
- if (!ret) {
+ if (ret == NULL) {
#ifndef OPENSSL_NO_ENGINE
- if (e)
- ENGINE_finish(e);
+ ENGINE_finish(e);
#endif
EVPerror(ERR_R_MALLOC_FAILURE);
return NULL;
@@ -394,10 +393,7 @@ EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
EVP_PKEY_free(ctx->pkey);
EVP_PKEY_free(ctx->peerkey);
#ifndef OPENSSL_NO_ENGINE
- if (ctx->engine)
- /* The EVP_PKEY_CTX we used belongs to an ENGINE, release the
- * functional reference we held for this reason. */
- ENGINE_finish(ctx->engine);
+ ENGINE_finish(ctx->engine);
#endif
free(ctx);
}
diff --git a/lib/libcrypto/pem/pem_lib.c b/lib/libcrypto/pem/pem_lib.c
index 0f7c36d21c8..89e9e9a7ec7 100644
--- a/lib/libcrypto/pem/pem_lib.c
+++ b/lib/libcrypto/pem/pem_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pem_lib.c,v 1.45 2017/05/02 03:59:44 deraadt Exp $ */
+/* $OpenBSD: pem_lib.c,v 1.46 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -227,8 +227,7 @@ check_pem(const char *nm, const char *name)
else
r = 0;
#ifndef OPENSSL_NO_ENGINE
- if (e)
- ENGINE_finish(e);
+ ENGINE_finish(e);
#endif
return r;
}
diff --git a/lib/libcrypto/rsa/rsa_lib.c b/lib/libcrypto/rsa/rsa_lib.c
index 544846f8252..84e1dc7eaf7 100644
--- a/lib/libcrypto/rsa/rsa_lib.c
+++ b/lib/libcrypto/rsa/rsa_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rsa_lib.c,v 1.36 2018/02/20 17:42:32 tb Exp $ */
+/* $OpenBSD: rsa_lib.c,v 1.37 2018/04/14 07:09:21 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -114,10 +114,8 @@ RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
if (mtmp->finish)
mtmp->finish(rsa);
#ifndef OPENSSL_NO_ENGINE
- if (rsa->engine) {
- ENGINE_finish(rsa->engine);
- rsa->engine = NULL;
- }
+ ENGINE_finish(rsa->engine);
+ rsa->engine = NULL;
#endif
rsa->meth = meth;
if (meth->init)
@@ -149,7 +147,7 @@ RSA_new_method(ENGINE *engine)
ret->engine = ENGINE_get_default_RSA();
if (ret->engine) {
ret->meth = ENGINE_get_RSA(ret->engine);
- if (!ret->meth) {
+ if (ret->meth == NULL) {
RSAerror(ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
free(ret);
@@ -177,8 +175,7 @@ RSA_new_method(ENGINE *engine)
ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW;
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data)) {
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine)
- ENGINE_finish(ret->engine);
+ ENGINE_finish(ret->engine);
#endif
free(ret);
return NULL;
@@ -186,8 +183,7 @@ RSA_new_method(ENGINE *engine)
if (ret->meth->init != NULL && !ret->meth->init(ret)) {
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine)
- ENGINE_finish(ret->engine);
+ ENGINE_finish(ret->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
free(ret);
@@ -211,8 +207,7 @@ RSA_free(RSA *r)
if (r->meth->finish)
r->meth->finish(r);
#ifndef OPENSSL_NO_ENGINE
- if (r->engine)
- ENGINE_finish(r->engine);
+ ENGINE_finish(r->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);