summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine/eng_ctrl.c
diff options
context:
space:
mode:
authorbeck <>2017-01-29 17:49:23 +0000
committerbeck <>2017-01-29 17:49:23 +0000
commit957b11334a7afb14537322f0e4795b2e368b3f59 (patch)
tree1a54abba678898ee5270ae4f3404a50ee9a92eea /src/lib/libcrypto/engine/eng_ctrl.c
parentdf96e020e729c6c37a8c7fe311fdd1fe6a8718c5 (diff)
downloadopenbsd-957b11334a7afb14537322f0e4795b2e368b3f59.tar.gz
openbsd-957b11334a7afb14537322f0e4795b2e368b3f59.tar.bz2
openbsd-957b11334a7afb14537322f0e4795b2e368b3f59.zip
Send the function codes from the error functions to the bit bucket,
as was done earlier in libssl. Thanks inoguchi@ for noticing libssl had more reacharounds into this. ok jsing@ inoguchi@
Diffstat (limited to 'src/lib/libcrypto/engine/eng_ctrl.c')
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c54
1 files changed, 20 insertions, 34 deletions
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
index bf832dc626..1a3c25fbae 100644
--- a/src/lib/libcrypto/engine/eng_ctrl.c
+++ b/src/lib/libcrypto/engine/eng_ctrl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_ctrl.c,v 1.10 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_ctrl.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -125,8 +125,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
125 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || 125 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
126 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) { 126 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) {
127 if (s == NULL) { 127 if (s == NULL) {
128 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 128 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
129 ERR_R_PASSED_NULL_PARAMETER);
130 return -1; 129 return -1;
131 } 130 }
132 } 131 }
@@ -134,8 +133,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
134 if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) { 133 if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) {
135 if ((e->cmd_defns == NULL) || 134 if ((e->cmd_defns == NULL) ||
136 ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) { 135 ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) {
137 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 136 ENGINEerror(ENGINE_R_INVALID_CMD_NAME);
138 ENGINE_R_INVALID_CMD_NAME);
139 return -1; 137 return -1;
140 } 138 }
141 return e->cmd_defns[idx].cmd_num; 139 return e->cmd_defns[idx].cmd_num;
@@ -144,8 +142,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
144 * valie command number - so we need to conduct a search. */ 142 * valie command number - so we need to conduct a search. */
145 if ((e->cmd_defns == NULL) || 143 if ((e->cmd_defns == NULL) ||
146 ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) { 144 ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) {
147 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 145 ENGINEerror(ENGINE_R_INVALID_CMD_NUMBER);
148 ENGINE_R_INVALID_CMD_NUMBER);
149 return -1; 146 return -1;
150 } 147 }
151 /* Now the logic splits depending on command type */ 148 /* Now the logic splits depending on command type */
@@ -188,7 +185,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
188 } 185 }
189 186
190 /* Shouldn't really be here ... */ 187 /* Shouldn't really be here ... */
191 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, ENGINE_R_INTERNAL_LIST_ERROR); 188 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
192 return -1; 189 return -1;
193} 190}
194 191
@@ -198,7 +195,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
198 int ctrl_exists, ref_exists; 195 int ctrl_exists, ref_exists;
199 196
200 if (e == NULL) { 197 if (e == NULL) {
201 ENGINEerr(ENGINE_F_ENGINE_CTRL, ERR_R_PASSED_NULL_PARAMETER); 198 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
202 return 0; 199 return 0;
203 } 200 }
204 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 201 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -206,7 +203,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
206 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 203 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
207 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); 204 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
208 if (!ref_exists) { 205 if (!ref_exists) {
209 ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_REFERENCE); 206 ENGINEerror(ENGINE_R_NO_REFERENCE);
210 return 0; 207 return 0;
211 } 208 }
212 /* Intercept any "root-level" commands before trying to hand them on to 209 /* Intercept any "root-level" commands before trying to hand them on to
@@ -225,8 +222,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
225 if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) 222 if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
226 return int_ctrl_helper(e, cmd, i, p, f); 223 return int_ctrl_helper(e, cmd, i, p, f);
227 if (!ctrl_exists) { 224 if (!ctrl_exists) {
228 ENGINEerr(ENGINE_F_ENGINE_CTRL, 225 ENGINEerror(ENGINE_R_NO_CONTROL_FUNCTION);
229 ENGINE_R_NO_CONTROL_FUNCTION);
230 /* For these cmd-related functions, failure is indicated 226 /* For these cmd-related functions, failure is indicated
231 * by a -1 return value (because 0 is used as a valid 227 * by a -1 return value (because 0 is used as a valid
232 * return in some places). */ 228 * return in some places). */
@@ -237,7 +233,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
237 } 233 }
238 /* Anything else requires a ctrl() handler to exist. */ 234 /* Anything else requires a ctrl() handler to exist. */
239 if (!ctrl_exists) { 235 if (!ctrl_exists) {
240 ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION); 236 ENGINEerror(ENGINE_R_NO_CONTROL_FUNCTION);
241 return 0; 237 return 0;
242 } 238 }
243 return e->ctrl(e, cmd, i, p, f); 239 return e->ctrl(e, cmd, i, p, f);
@@ -250,8 +246,7 @@ ENGINE_cmd_is_executable(ENGINE *e, int cmd)
250 246
251 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, 247 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd,
252 NULL, NULL)) < 0) { 248 NULL, NULL)) < 0) {
253 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, 249 ENGINEerror(ENGINE_R_INVALID_CMD_NUMBER);
254 ENGINE_R_INVALID_CMD_NUMBER);
255 return 0; 250 return 0;
256 } 251 }
257 if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) && 252 if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
@@ -268,8 +263,7 @@ ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p,
268 int num; 263 int num;
269 264
270 if ((e == NULL) || (cmd_name == NULL)) { 265 if ((e == NULL) || (cmd_name == NULL)) {
271 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, 266 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
272 ERR_R_PASSED_NULL_PARAMETER);
273 return 0; 267 return 0;
274 } 268 }
275 if ((e->ctrl == NULL) || 269 if ((e->ctrl == NULL) ||
@@ -285,7 +279,7 @@ ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p,
285 ERR_clear_error(); 279 ERR_clear_error();
286 return 1; 280 return 1;
287 } 281 }
288 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, ENGINE_R_INVALID_CMD_NAME); 282 ENGINEerror(ENGINE_R_INVALID_CMD_NAME);
289 return 0; 283 return 0;
290 } 284 }
291 285
@@ -306,8 +300,7 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
306 char *ptr; 300 char *ptr;
307 301
308 if ((e == NULL) || (cmd_name == NULL)) { 302 if ((e == NULL) || (cmd_name == NULL)) {
309 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 303 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
310 ERR_R_PASSED_NULL_PARAMETER);
311 return 0; 304 return 0;
312 } 305 }
313 if ((e->ctrl == NULL) || 306 if ((e->ctrl == NULL) ||
@@ -323,29 +316,25 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
323 ERR_clear_error(); 316 ERR_clear_error();
324 return 1; 317 return 1;
325 } 318 }
326 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 319 ENGINEerror(ENGINE_R_INVALID_CMD_NAME);
327 ENGINE_R_INVALID_CMD_NAME);
328 return 0; 320 return 0;
329 } 321 }
330 if (!ENGINE_cmd_is_executable(e, num)) { 322 if (!ENGINE_cmd_is_executable(e, num)) {
331 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 323 ENGINEerror(ENGINE_R_CMD_NOT_EXECUTABLE);
332 ENGINE_R_CMD_NOT_EXECUTABLE);
333 return 0; 324 return 0;
334 } 325 }
335 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, 326 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
336 NULL, NULL)) < 0) { 327 NULL, NULL)) < 0) {
337 /* Shouldn't happen, given that ENGINE_cmd_is_executable() 328 /* Shouldn't happen, given that ENGINE_cmd_is_executable()
338 * returned success. */ 329 * returned success. */
339 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 330 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
340 ENGINE_R_INTERNAL_LIST_ERROR);
341 return 0; 331 return 0;
342 } 332 }
343 /* If the command takes no input, there must be no input. And vice 333 /* If the command takes no input, there must be no input. And vice
344 * versa. */ 334 * versa. */
345 if (flags & ENGINE_CMD_FLAG_NO_INPUT) { 335 if (flags & ENGINE_CMD_FLAG_NO_INPUT) {
346 if (arg != NULL) { 336 if (arg != NULL) {
347 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 337 ENGINEerror(ENGINE_R_COMMAND_TAKES_NO_INPUT);
348 ENGINE_R_COMMAND_TAKES_NO_INPUT);
349 return 0; 338 return 0;
350 } 339 }
351 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 340 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
@@ -359,8 +348,7 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
359 } 348 }
360 /* So, we require input */ 349 /* So, we require input */
361 if (arg == NULL) { 350 if (arg == NULL) {
362 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 351 ENGINEerror(ENGINE_R_COMMAND_TAKES_INPUT);
363 ENGINE_R_COMMAND_TAKES_INPUT);
364 return 0; 352 return 0;
365 } 353 }
366 /* If it takes string input, that's easy */ 354 /* If it takes string input, that's easy */
@@ -375,14 +363,12 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
375 * should never happen though, because ENGINE_cmd_is_executable() was 363 * should never happen though, because ENGINE_cmd_is_executable() was
376 * used. */ 364 * used. */
377 if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) { 365 if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) {
378 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 366 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
379 ENGINE_R_INTERNAL_LIST_ERROR);
380 return 0; 367 return 0;
381 } 368 }
382 l = strtol(arg, &ptr, 10); 369 l = strtol(arg, &ptr, 10);
383 if ((arg == ptr) || (*ptr != '\0')) { 370 if ((arg == ptr) || (*ptr != '\0')) {
384 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 371 ENGINEerror(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
385 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
386 return 0; 372 return 0;
387 } 373 }
388 /* Force the result of the control command to 0 or 1, for the reasons 374 /* Force the result of the control command to 0 or 1, for the reasons