From e2303054291a1a9cf6ea192af2df63e77c3f65fd 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 ++--- src/regress/lib/libcrypto/engine/enginetest.c | 17 +++++++---------- src/regress/lib/libcrypto/free/freenull.c | 8 +++++++- 8 files changed, 41 insertions(+), 41 deletions(-) (limited to 'src') 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; } diff --git a/src/regress/lib/libcrypto/engine/enginetest.c b/src/regress/lib/libcrypto/engine/enginetest.c index bb2472a31d..f39857d6d6 100644 --- a/src/regress/lib/libcrypto/engine/enginetest.c +++ b/src/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/src/regress/lib/libcrypto/free/freenull.c b/src/regress/lib/libcrypto/free/freenull.c index 5fe6c1a3ed..89cbd82539 100644 --- a/src/regress/lib/libcrypto/free/freenull.c +++ b/src/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 * @@ -17,6 +17,9 @@ #include #include +#ifndef OPENSSL_NO_ENGINE +#include +#endif #include #include #include @@ -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); -- cgit v1.2.3-55-g6feb