From 1e9445503c3ea65f8c138ab5dc555db0f1db91a7 Mon Sep 17 00:00:00 2001 From: tb <> Date: Sat, 14 Apr 2018 07:18:37 +0000 Subject: Make ENGINE_free() succeed on NULL. Matches OpenSSL's behavior and simplifies the caller side. tested by & ok inoguchi; discussed with schwarze --- src/lib/libcrypto/engine/eng_aesni.c | 12 ++++++------ src/lib/libcrypto/engine/eng_cnf.c | 5 ++--- src/lib/libcrypto/engine/eng_lib.c | 8 +++----- src/lib/libcrypto/engine/eng_openssl.c | 6 +++--- src/lib/libcrypto/engine/eng_padlock.c | 21 +++++++++++---------- src/lib/libcrypto/ts/ts_conf.c | 5 ++--- 6 files changed, 27 insertions(+), 30 deletions(-) (limited to 'src/lib/libcrypto') diff --git a/src/lib/libcrypto/engine/eng_aesni.c b/src/lib/libcrypto/engine/eng_aesni.c index cd14bbc8cd..586f74792a 100644 --- a/src/lib/libcrypto/engine/eng_aesni.c +++ b/src/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 @@ -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/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c index 2ac077d492..24358af8cd 100644 --- a/src/lib/libcrypto/engine/eng_cnf.c +++ b/src/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/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c index 11ad771109..1aedcb18c6 100644 --- a/src/lib/libcrypto/engine/eng_lib.c +++ b/src/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/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c index 6154aebdee..f8f6c8f58c 100644 --- a/src/lib/libcrypto/engine/eng_openssl.c +++ b/src/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/src/lib/libcrypto/engine/eng_padlock.c b/src/lib/libcrypto/engine/eng_padlock.c index 4f2d426a06..0281ab810c 100644 --- a/src/lib/libcrypto/engine/eng_padlock.c +++ b/src/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 @@ -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/src/lib/libcrypto/ts/ts_conf.c b/src/lib/libcrypto/ts/ts_conf.c index c223aa3d46..41d185ee5a 100644 --- a/src/lib/libcrypto/ts/ts_conf.c +++ b/src/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; } -- cgit v1.2.3-55-g6feb