summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2018-04-14 07:18:37 +0000
committertb <tb@openbsd.org>2018-04-14 07:18:37 +0000
commite6afdd5eed7ac14c5f89dee26d6b4f12bd45dd3a (patch)
tree3d5b78231c934a07e6f55f7f97d298f948f18a70
parentmake ENGINE_finish() succeed on NULL and simplify callers as in (diff)
downloadwireguard-openbsd-e6afdd5eed7ac14c5f89dee26d6b4f12bd45dd3a.tar.xz
wireguard-openbsd-e6afdd5eed7ac14c5f89dee26d6b4f12bd45dd3a.zip
Make ENGINE_free() succeed on NULL. Matches OpenSSL's behavior and
simplifies the caller side. tested by & ok inoguchi; discussed with schwarze
-rw-r--r--lib/libcrypto/engine/eng_aesni.c12
-rw-r--r--lib/libcrypto/engine/eng_cnf.c5
-rw-r--r--lib/libcrypto/engine/eng_lib.c8
-rw-r--r--lib/libcrypto/engine/eng_openssl.c6
-rw-r--r--lib/libcrypto/engine/eng_padlock.c21
-rw-r--r--lib/libcrypto/ts/ts_conf.c5
-rw-r--r--regress/lib/libcrypto/engine/enginetest.c17
-rw-r--r--regress/lib/libcrypto/free/freenull.c8
8 files changed, 41 insertions, 41 deletions
diff --git a/lib/libcrypto/engine/eng_aesni.c b/lib/libcrypto/engine/eng_aesni.c
index cd14bbc8cd4..586f74792ac 100644
--- a/lib/libcrypto/engine/eng_aesni.c
+++ b/lib/libcrypto/engine/eng_aesni.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eng_aesni.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
+/* $OpenBSD: eng_aesni.c,v 1.11 2018/04/14 07:18:37 tb Exp $ */
/*
* Support for Intel AES-NI intruction set
* Author: Huang Ying <ying.huang@intel.com>
@@ -102,12 +102,12 @@ void ENGINE_load_aesni(void)
/* On non-x86 CPUs it just returns. */
#ifdef COMPILE_HW_AESNI
ENGINE *toadd = ENGINE_aesni();
- if (!toadd)
+ if (toadd == NULL)
return;
- ENGINE_add (toadd);
- ENGINE_register_complete (toadd);
- ENGINE_free (toadd);
- ERR_clear_error ();
+ ENGINE_add(toadd);
+ ENGINE_register_complete(toadd);
+ ENGINE_free(toadd);
+ ERR_clear_error();
#endif
}
diff --git a/lib/libcrypto/engine/eng_cnf.c b/lib/libcrypto/engine/eng_cnf.c
index 2ac077d4920..24358af8cd2 100644
--- a/lib/libcrypto/engine/eng_cnf.c
+++ b/lib/libcrypto/engine/eng_cnf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eng_cnf.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
+/* $OpenBSD: eng_cnf.c,v 1.15 2018/04/14 07:18:37 tb Exp $ */
/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
* project 2001.
*/
@@ -200,8 +200,7 @@ err:
"section=%s, name=%s, value=%s",
ecmd->section, ecmd->name, ecmd->value);
}
- if (e)
- ENGINE_free(e);
+ ENGINE_free(e);
return ret;
}
diff --git a/lib/libcrypto/engine/eng_lib.c b/lib/libcrypto/engine/eng_lib.c
index 11ad7711097..1aedcb18c66 100644
--- a/lib/libcrypto/engine/eng_lib.c
+++ b/lib/libcrypto/engine/eng_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eng_lib.c,v 1.13 2018/03/17 16:20:01 beck Exp $ */
+/* $OpenBSD: eng_lib.c,v 1.14 2018/04/14 07:18:37 tb Exp $ */
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
* project 2000.
*/
@@ -115,10 +115,8 @@ engine_free_util(ENGINE *e, int locked)
{
int i;
- if (e == NULL) {
- ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
+ if (e == NULL)
+ return 1;
if (locked)
i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE);
else
diff --git a/lib/libcrypto/engine/eng_openssl.c b/lib/libcrypto/engine/eng_openssl.c
index 6154aebdee7..f8f6c8f58cd 100644
--- a/lib/libcrypto/engine/eng_openssl.c
+++ b/lib/libcrypto/engine/eng_openssl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eng_openssl.c,v 1.12 2015/12/07 03:30:09 bcook Exp $ */
+/* $OpenBSD: eng_openssl.c,v 1.13 2018/04/14 07:18:37 tb Exp $ */
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
* project 2000.
*/
@@ -177,7 +177,7 @@ engine_openssl(void)
{
ENGINE *ret = ENGINE_new();
- if (!ret)
+ if (ret == NULL)
return NULL;
if (!bind_helper(ret)) {
ENGINE_free(ret);
@@ -191,7 +191,7 @@ ENGINE_load_openssl(void)
{
ENGINE *toadd = engine_openssl();
- if (!toadd)
+ if (toadd == NULL)
return;
(void) ENGINE_add(toadd);
/* If the "add" worked, it gets a structural reference. So either way,
diff --git a/lib/libcrypto/engine/eng_padlock.c b/lib/libcrypto/engine/eng_padlock.c
index 4f2d426a068..0281ab810c6 100644
--- a/lib/libcrypto/engine/eng_padlock.c
+++ b/lib/libcrypto/engine/eng_padlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eng_padlock.c,v 1.15 2016/11/04 13:56:05 miod Exp $ */
+/* $OpenBSD: eng_padlock.c,v 1.16 2018/04/14 07:18:37 tb Exp $ */
/*
* Support for VIA PadLock Advanced Cryptography Engine (ACE)
* Written by Michal Ludvig <michal@logix.cz>
@@ -108,19 +108,21 @@
#ifdef OPENSSL_NO_DYNAMIC_ENGINE
#ifdef COMPILE_HW_PADLOCK
-static ENGINE *ENGINE_padlock (void);
+static ENGINE *ENGINE_padlock(void);
#endif
-void ENGINE_load_padlock (void)
+void
+ENGINE_load_padlock(void)
{
/* On non-x86 CPUs it just returns. */
#ifdef COMPILE_HW_PADLOCK
- ENGINE *toadd = ENGINE_padlock ();
- if (!toadd)
+ ENGINE *toadd = ENGINE_padlock();
+
+ if (toadd == NULL)
return;
- ENGINE_add (toadd);
- ENGINE_free (toadd);
- ERR_clear_error ();
+ ENGINE_add(toadd);
+ ENGINE_free(toadd);
+ ERR_clear_error();
#endif
}
@@ -203,9 +205,8 @@ ENGINE_padlock(void)
{
ENGINE *eng = ENGINE_new();
- if (!eng) {
+ if (eng == NULL)
return NULL;
- }
if (!padlock_bind_helper(eng)) {
ENGINE_free(eng);
diff --git a/lib/libcrypto/ts/ts_conf.c b/lib/libcrypto/ts/ts_conf.c
index c223aa3d463..41d185ee5a0 100644
--- a/lib/libcrypto/ts/ts_conf.c
+++ b/lib/libcrypto/ts/ts_conf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ts_conf.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
+/* $OpenBSD: ts_conf.c,v 1.11 2018/04/14 07:18:37 tb Exp $ */
/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
* project 2002.
*/
@@ -248,8 +248,7 @@ err:
TSerror(TS_R_COULD_NOT_SET_ENGINE);
ERR_asprintf_error_data("engine:%s", name);
}
- if (e)
- ENGINE_free(e);
+ ENGINE_free(e);
return ret;
}
diff --git a/regress/lib/libcrypto/engine/enginetest.c b/regress/lib/libcrypto/engine/enginetest.c
index bb2472a31d6..f39857d6d61 100644
--- a/regress/lib/libcrypto/engine/enginetest.c
+++ b/regress/lib/libcrypto/engine/enginetest.c
@@ -129,8 +129,7 @@ int main(int argc, char *argv[])
printf("Remove failed!\n");
goto end;
}
- if (ptr)
- ENGINE_free(ptr);
+ ENGINE_free(ptr);
display_engine_list();
if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
printf("Add failed!\n");
@@ -178,8 +177,7 @@ int main(int argc, char *argv[])
if (!ENGINE_remove(ptr))
printf("Remove failed!i - probably no hardware "
"support present.\n");
- if (ptr)
- ENGINE_free(ptr);
+ ENGINE_free(ptr);
display_engine_list();
if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
@@ -231,13 +229,12 @@ int main(int argc, char *argv[])
end:
if (to_return)
ERR_print_errors_fp(stderr);
- if (new_h1) ENGINE_free(new_h1);
- if (new_h2) ENGINE_free(new_h2);
- if (new_h3) ENGINE_free(new_h3);
- if (new_h4) ENGINE_free(new_h4);
+ ENGINE_free(new_h1);
+ ENGINE_free(new_h2);
+ ENGINE_free(new_h3);
+ ENGINE_free(new_h4);
for (loop = 0; loop < 512; loop++)
- if (block[loop])
- ENGINE_free(block[loop]);
+ ENGINE_free(block[loop]);
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
diff --git a/regress/lib/libcrypto/free/freenull.c b/regress/lib/libcrypto/free/freenull.c
index 5fe6c1a3ed6..89cbd825395 100644
--- a/regress/lib/libcrypto/free/freenull.c
+++ b/regress/lib/libcrypto/free/freenull.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: freenull.c,v 1.6 2018/02/07 05:07:39 jsing Exp $ */
+/* $OpenBSD: freenull.c,v 1.7 2018/04/14 07:18:37 tb Exp $ */
/*
* Copyright (c) 2017 Bob Beck <beck@openbsd.org>
*
@@ -17,6 +17,9 @@
#include <openssl/asn1.h>
#include <openssl/ocsp.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
#include <openssl/pkcs12.h>
#include <openssl/ts.h>
#include <openssl/ui.h>
@@ -55,6 +58,9 @@ main(int argc, char **argv)
EC_KEY_free(NULL);
EC_POINT_clear_free(NULL);
EC_POINT_free(NULL);
+#ifndef OPENSSL_NO_ENGINE
+ ENGINE_free(NULL);
+#endif
EVP_CIPHER_CTX_free(NULL);
EVP_PKEY_CTX_free(NULL);
EVP_PKEY_free(NULL);