summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2018-04-14 07:18:37 +0000
committertb <>2018-04-14 07:18:37 +0000
commit1e9445503c3ea65f8c138ab5dc555db0f1db91a7 (patch)
tree27f20ba7d1bd380c7995e6d349ae1b5f8b90cc6d
parenta32b35170819e9b07e0183d19aee21b9a246943b (diff)
downloadopenbsd-1e9445503c3ea65f8c138ab5dc555db0f1db91a7.tar.gz
openbsd-1e9445503c3ea65f8c138ab5dc555db0f1db91a7.tar.bz2
openbsd-1e9445503c3ea65f8c138ab5dc555db0f1db91a7.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--src/lib/libcrypto/engine/eng_aesni.c12
-rw-r--r--src/lib/libcrypto/engine/eng_cnf.c5
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c8
-rw-r--r--src/lib/libcrypto/engine/eng_openssl.c6
-rw-r--r--src/lib/libcrypto/engine/eng_padlock.c21
-rw-r--r--src/lib/libcrypto/ts/ts_conf.c5
-rw-r--r--src/regress/lib/libcrypto/engine/enginetest.c17
-rw-r--r--src/regress/lib/libcrypto/free/freenull.c8
8 files changed, 41 insertions, 41 deletions
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 @@
1/* $OpenBSD: eng_aesni.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: eng_aesni.c,v 1.11 2018/04/14 07:18:37 tb Exp $ */
2/* 2/*
3 * Support for Intel AES-NI intruction set 3 * Support for Intel AES-NI intruction set
4 * Author: Huang Ying <ying.huang@intel.com> 4 * Author: Huang Ying <ying.huang@intel.com>
@@ -102,12 +102,12 @@ void ENGINE_load_aesni(void)
102/* On non-x86 CPUs it just returns. */ 102/* On non-x86 CPUs it just returns. */
103#ifdef COMPILE_HW_AESNI 103#ifdef COMPILE_HW_AESNI
104 ENGINE *toadd = ENGINE_aesni(); 104 ENGINE *toadd = ENGINE_aesni();
105 if (!toadd) 105 if (toadd == NULL)
106 return; 106 return;
107 ENGINE_add (toadd); 107 ENGINE_add(toadd);
108 ENGINE_register_complete (toadd); 108 ENGINE_register_complete(toadd);
109 ENGINE_free (toadd); 109 ENGINE_free(toadd);
110 ERR_clear_error (); 110 ERR_clear_error();
111#endif 111#endif
112} 112}
113 113
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 @@
1/* $OpenBSD: eng_cnf.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: eng_cnf.c,v 1.15 2018/04/14 07:18:37 tb Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -200,8 +200,7 @@ err:
200 "section=%s, name=%s, value=%s", 200 "section=%s, name=%s, value=%s",
201 ecmd->section, ecmd->name, ecmd->value); 201 ecmd->section, ecmd->name, ecmd->value);
202 } 202 }
203 if (e) 203 ENGINE_free(e);
204 ENGINE_free(e);
205 return ret; 204 return ret;
206} 205}
207 206
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 @@
1/* $OpenBSD: eng_lib.c,v 1.13 2018/03/17 16:20:01 beck Exp $ */ 1/* $OpenBSD: eng_lib.c,v 1.14 2018/04/14 07:18:37 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -115,10 +115,8 @@ engine_free_util(ENGINE *e, int locked)
115{ 115{
116 int i; 116 int i;
117 117
118 if (e == NULL) { 118 if (e == NULL)
119 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); 119 return 1;
120 return 0;
121 }
122 if (locked) 120 if (locked)
123 i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE); 121 i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE);
124 else 122 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 @@
1/* $OpenBSD: eng_openssl.c,v 1.12 2015/12/07 03:30:09 bcook Exp $ */ 1/* $OpenBSD: eng_openssl.c,v 1.13 2018/04/14 07:18:37 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -177,7 +177,7 @@ engine_openssl(void)
177{ 177{
178 ENGINE *ret = ENGINE_new(); 178 ENGINE *ret = ENGINE_new();
179 179
180 if (!ret) 180 if (ret == NULL)
181 return NULL; 181 return NULL;
182 if (!bind_helper(ret)) { 182 if (!bind_helper(ret)) {
183 ENGINE_free(ret); 183 ENGINE_free(ret);
@@ -191,7 +191,7 @@ ENGINE_load_openssl(void)
191{ 191{
192 ENGINE *toadd = engine_openssl(); 192 ENGINE *toadd = engine_openssl();
193 193
194 if (!toadd) 194 if (toadd == NULL)
195 return; 195 return;
196 (void) ENGINE_add(toadd); 196 (void) ENGINE_add(toadd);
197 /* If the "add" worked, it gets a structural reference. So either way, 197 /* 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 @@
1/* $OpenBSD: eng_padlock.c,v 1.15 2016/11/04 13:56:05 miod Exp $ */ 1/* $OpenBSD: eng_padlock.c,v 1.16 2018/04/14 07:18:37 tb Exp $ */
2/* 2/*
3 * Support for VIA PadLock Advanced Cryptography Engine (ACE) 3 * Support for VIA PadLock Advanced Cryptography Engine (ACE)
4 * Written by Michal Ludvig <michal@logix.cz> 4 * Written by Michal Ludvig <michal@logix.cz>
@@ -108,19 +108,21 @@
108 108
109#ifdef OPENSSL_NO_DYNAMIC_ENGINE 109#ifdef OPENSSL_NO_DYNAMIC_ENGINE
110#ifdef COMPILE_HW_PADLOCK 110#ifdef COMPILE_HW_PADLOCK
111static ENGINE *ENGINE_padlock (void); 111static ENGINE *ENGINE_padlock(void);
112#endif 112#endif
113 113
114void ENGINE_load_padlock (void) 114void
115ENGINE_load_padlock(void)
115{ 116{
116/* On non-x86 CPUs it just returns. */ 117/* On non-x86 CPUs it just returns. */
117#ifdef COMPILE_HW_PADLOCK 118#ifdef COMPILE_HW_PADLOCK
118 ENGINE *toadd = ENGINE_padlock (); 119 ENGINE *toadd = ENGINE_padlock();
119 if (!toadd) 120
121 if (toadd == NULL)
120 return; 122 return;
121 ENGINE_add (toadd); 123 ENGINE_add(toadd);
122 ENGINE_free (toadd); 124 ENGINE_free(toadd);
123 ERR_clear_error (); 125 ERR_clear_error();
124#endif 126#endif
125} 127}
126 128
@@ -203,9 +205,8 @@ ENGINE_padlock(void)
203{ 205{
204 ENGINE *eng = ENGINE_new(); 206 ENGINE *eng = ENGINE_new();
205 207
206 if (!eng) { 208 if (eng == NULL)
207 return NULL; 209 return NULL;
208 }
209 210
210 if (!padlock_bind_helper(eng)) { 211 if (!padlock_bind_helper(eng)) {
211 ENGINE_free(eng); 212 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 @@
1/* $OpenBSD: ts_conf.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: ts_conf.c,v 1.11 2018/04/14 07:18:37 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -248,8 +248,7 @@ err:
248 TSerror(TS_R_COULD_NOT_SET_ENGINE); 248 TSerror(TS_R_COULD_NOT_SET_ENGINE);
249 ERR_asprintf_error_data("engine:%s", name); 249 ERR_asprintf_error_data("engine:%s", name);
250 } 250 }
251 if (e) 251 ENGINE_free(e);
252 ENGINE_free(e);
253 return ret; 252 return ret;
254} 253}
255 254
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[])
129 printf("Remove failed!\n"); 129 printf("Remove failed!\n");
130 goto end; 130 goto end;
131 } 131 }
132 if (ptr) 132 ENGINE_free(ptr);
133 ENGINE_free(ptr);
134 display_engine_list(); 133 display_engine_list();
135 if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) { 134 if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
136 printf("Add failed!\n"); 135 printf("Add failed!\n");
@@ -178,8 +177,7 @@ int main(int argc, char *argv[])
178 if (!ENGINE_remove(ptr)) 177 if (!ENGINE_remove(ptr))
179 printf("Remove failed!i - probably no hardware " 178 printf("Remove failed!i - probably no hardware "
180 "support present.\n"); 179 "support present.\n");
181 if (ptr) 180 ENGINE_free(ptr);
182 ENGINE_free(ptr);
183 display_engine_list(); 181 display_engine_list();
184 182
185 if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) { 183 if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
@@ -231,13 +229,12 @@ int main(int argc, char *argv[])
231end: 229end:
232 if (to_return) 230 if (to_return)
233 ERR_print_errors_fp(stderr); 231 ERR_print_errors_fp(stderr);
234 if (new_h1) ENGINE_free(new_h1); 232 ENGINE_free(new_h1);
235 if (new_h2) ENGINE_free(new_h2); 233 ENGINE_free(new_h2);
236 if (new_h3) ENGINE_free(new_h3); 234 ENGINE_free(new_h3);
237 if (new_h4) ENGINE_free(new_h4); 235 ENGINE_free(new_h4);
238 for (loop = 0; loop < 512; loop++) 236 for (loop = 0; loop < 512; loop++)
239 if (block[loop]) 237 ENGINE_free(block[loop]);
240 ENGINE_free(block[loop]);
241 ENGINE_cleanup(); 238 ENGINE_cleanup();
242 CRYPTO_cleanup_all_ex_data(); 239 CRYPTO_cleanup_all_ex_data();
243 ERR_free_strings(); 240 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 @@
1/* $OpenBSD: freenull.c,v 1.6 2018/02/07 05:07:39 jsing Exp $ */ 1/* $OpenBSD: freenull.c,v 1.7 2018/04/14 07:18:37 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2017 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2017 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -17,6 +17,9 @@
17 17
18#include <openssl/asn1.h> 18#include <openssl/asn1.h>
19#include <openssl/ocsp.h> 19#include <openssl/ocsp.h>
20#ifndef OPENSSL_NO_ENGINE
21#include <openssl/engine.h>
22#endif
20#include <openssl/pkcs12.h> 23#include <openssl/pkcs12.h>
21#include <openssl/ts.h> 24#include <openssl/ts.h>
22#include <openssl/ui.h> 25#include <openssl/ui.h>
@@ -55,6 +58,9 @@ main(int argc, char **argv)
55 EC_KEY_free(NULL); 58 EC_KEY_free(NULL);
56 EC_POINT_clear_free(NULL); 59 EC_POINT_clear_free(NULL);
57 EC_POINT_free(NULL); 60 EC_POINT_free(NULL);
61#ifndef OPENSSL_NO_ENGINE
62 ENGINE_free(NULL);
63#endif
58 EVP_CIPHER_CTX_free(NULL); 64 EVP_CIPHER_CTX_free(NULL);
59 EVP_PKEY_CTX_free(NULL); 65 EVP_PKEY_CTX_free(NULL);
60 EVP_PKEY_free(NULL); 66 EVP_PKEY_free(NULL);