diff options
author | beck <> | 2017-01-29 17:49:23 +0000 |
---|---|---|
committer | beck <> | 2017-01-29 17:49:23 +0000 |
commit | 957b11334a7afb14537322f0e4795b2e368b3f59 (patch) | |
tree | 1a54abba678898ee5270ae4f3404a50ee9a92eea /src/lib/libcrypto/ui/ui_lib.c | |
parent | df96e020e729c6c37a8c7fe311fdd1fe6a8718c5 (diff) | |
download | openbsd-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/ui/ui_lib.c')
-rw-r--r-- | src/lib/libcrypto/ui/ui_lib.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c index 80f0992ddd..e551030729 100644 --- a/src/lib/libcrypto/ui/ui_lib.c +++ b/src/lib/libcrypto/ui/ui_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ui_lib.c,v 1.31 2016/04/28 16:42:28 tedu Exp $ */ | 1 | /* $OpenBSD: ui_lib.c,v 1.32 2017/01/29 17:49:23 beck Exp $ */ |
2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL |
3 | * project 2001. | 3 | * project 2001. |
4 | */ | 4 | */ |
@@ -81,7 +81,7 @@ UI_new_method(const UI_METHOD *method) | |||
81 | 81 | ||
82 | ret = malloc(sizeof(UI)); | 82 | ret = malloc(sizeof(UI)); |
83 | if (ret == NULL) { | 83 | if (ret == NULL) { |
84 | UIerr(UI_F_UI_NEW_METHOD, ERR_R_MALLOC_FAILURE); | 84 | UIerror(ERR_R_MALLOC_FAILURE); |
85 | return NULL; | 85 | return NULL; |
86 | } | 86 | } |
87 | if (method == NULL) | 87 | if (method == NULL) |
@@ -143,11 +143,10 @@ general_allocate_prompt(UI *ui, const char *prompt, int prompt_freeable, | |||
143 | UI_STRING *ret = NULL; | 143 | UI_STRING *ret = NULL; |
144 | 144 | ||
145 | if (prompt == NULL) { | 145 | if (prompt == NULL) { |
146 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, | 146 | UIerror(ERR_R_PASSED_NULL_PARAMETER); |
147 | ERR_R_PASSED_NULL_PARAMETER); | ||
148 | } else if ((type == UIT_PROMPT || type == UIT_VERIFY || | 147 | } else if ((type == UIT_PROMPT || type == UIT_VERIFY || |
149 | type == UIT_BOOLEAN) && result_buf == NULL) { | 148 | type == UIT_BOOLEAN) && result_buf == NULL) { |
150 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER); | 149 | UIerror(UI_R_NO_RESULT_BUFFER); |
151 | } else if ((ret = malloc(sizeof(UI_STRING)))) { | 150 | } else if ((ret = malloc(sizeof(UI_STRING)))) { |
152 | ret->out_string = prompt; | 151 | ret->out_string = prompt; |
153 | ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0; | 152 | ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0; |
@@ -192,16 +191,13 @@ general_allocate_boolean(UI *ui, const char *prompt, const char *action_desc, | |||
192 | const char *p; | 191 | const char *p; |
193 | 192 | ||
194 | if (ok_chars == NULL) { | 193 | if (ok_chars == NULL) { |
195 | UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, | 194 | UIerror(ERR_R_PASSED_NULL_PARAMETER); |
196 | ERR_R_PASSED_NULL_PARAMETER); | ||
197 | } else if (cancel_chars == NULL) { | 195 | } else if (cancel_chars == NULL) { |
198 | UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, | 196 | UIerror(ERR_R_PASSED_NULL_PARAMETER); |
199 | ERR_R_PASSED_NULL_PARAMETER); | ||
200 | } else { | 197 | } else { |
201 | for (p = ok_chars; *p; p++) { | 198 | for (p = ok_chars; *p; p++) { |
202 | if (strchr(cancel_chars, *p)) { | 199 | if (strchr(cancel_chars, *p)) { |
203 | UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, | 200 | UIerror(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS); |
204 | UI_R_COMMON_OK_AND_CANCEL_CHARACTERS); | ||
205 | } | 201 | } |
206 | } | 202 | } |
207 | 203 | ||
@@ -247,7 +243,7 @@ UI_dup_input_string(UI *ui, const char *prompt, int flags, char *result_buf, | |||
247 | if (prompt) { | 243 | if (prompt) { |
248 | prompt_copy = strdup(prompt); | 244 | prompt_copy = strdup(prompt); |
249 | if (prompt_copy == NULL) { | 245 | if (prompt_copy == NULL) { |
250 | UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE); | 246 | UIerror(ERR_R_MALLOC_FAILURE); |
251 | return 0; | 247 | return 0; |
252 | } | 248 | } |
253 | } | 249 | } |
@@ -272,7 +268,7 @@ UI_dup_verify_string(UI *ui, const char *prompt, int flags, | |||
272 | if (prompt) { | 268 | if (prompt) { |
273 | prompt_copy = strdup(prompt); | 269 | prompt_copy = strdup(prompt); |
274 | if (prompt_copy == NULL) { | 270 | if (prompt_copy == NULL) { |
275 | UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE); | 271 | UIerror(ERR_R_MALLOC_FAILURE); |
276 | return -1; | 272 | return -1; |
277 | } | 273 | } |
278 | } | 274 | } |
@@ -300,28 +296,28 @@ UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, | |||
300 | if (prompt) { | 296 | if (prompt) { |
301 | prompt_copy = strdup(prompt); | 297 | prompt_copy = strdup(prompt); |
302 | if (prompt_copy == NULL) { | 298 | if (prompt_copy == NULL) { |
303 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | 299 | UIerror(ERR_R_MALLOC_FAILURE); |
304 | goto err; | 300 | goto err; |
305 | } | 301 | } |
306 | } | 302 | } |
307 | if (action_desc) { | 303 | if (action_desc) { |
308 | action_desc_copy = strdup(action_desc); | 304 | action_desc_copy = strdup(action_desc); |
309 | if (action_desc_copy == NULL) { | 305 | if (action_desc_copy == NULL) { |
310 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | 306 | UIerror(ERR_R_MALLOC_FAILURE); |
311 | goto err; | 307 | goto err; |
312 | } | 308 | } |
313 | } | 309 | } |
314 | if (ok_chars) { | 310 | if (ok_chars) { |
315 | ok_chars_copy = strdup(ok_chars); | 311 | ok_chars_copy = strdup(ok_chars); |
316 | if (ok_chars_copy == NULL) { | 312 | if (ok_chars_copy == NULL) { |
317 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | 313 | UIerror(ERR_R_MALLOC_FAILURE); |
318 | goto err; | 314 | goto err; |
319 | } | 315 | } |
320 | } | 316 | } |
321 | if (cancel_chars) { | 317 | if (cancel_chars) { |
322 | cancel_chars_copy = strdup(cancel_chars); | 318 | cancel_chars_copy = strdup(cancel_chars); |
323 | if (cancel_chars_copy == NULL) { | 319 | if (cancel_chars_copy == NULL) { |
324 | UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); | 320 | UIerror(ERR_R_MALLOC_FAILURE); |
325 | goto err; | 321 | goto err; |
326 | } | 322 | } |
327 | } | 323 | } |
@@ -352,7 +348,7 @@ UI_dup_info_string(UI *ui, const char *text) | |||
352 | if (text) { | 348 | if (text) { |
353 | text_copy = strdup(text); | 349 | text_copy = strdup(text); |
354 | if (text_copy == NULL) { | 350 | if (text_copy == NULL) { |
355 | UIerr(UI_F_UI_DUP_INFO_STRING, ERR_R_MALLOC_FAILURE); | 351 | UIerror(ERR_R_MALLOC_FAILURE); |
356 | return -1; | 352 | return -1; |
357 | } | 353 | } |
358 | } | 354 | } |
@@ -375,7 +371,7 @@ UI_dup_error_string(UI *ui, const char *text) | |||
375 | if (text) { | 371 | if (text) { |
376 | text_copy = strdup(text); | 372 | text_copy = strdup(text); |
377 | if (text_copy == NULL) { | 373 | if (text_copy == NULL) { |
378 | UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE); | 374 | UIerror(ERR_R_MALLOC_FAILURE); |
379 | return -1; | 375 | return -1; |
380 | } | 376 | } |
381 | } | 377 | } |
@@ -426,11 +422,11 @@ const char * | |||
426 | UI_get0_result(UI *ui, int i) | 422 | UI_get0_result(UI *ui, int i) |
427 | { | 423 | { |
428 | if (i < 0) { | 424 | if (i < 0) { |
429 | UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL); | 425 | UIerror(UI_R_INDEX_TOO_SMALL); |
430 | return NULL; | 426 | return NULL; |
431 | } | 427 | } |
432 | if (i >= sk_UI_STRING_num(ui->strings)) { | 428 | if (i >= sk_UI_STRING_num(ui->strings)) { |
433 | UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_LARGE); | 429 | UIerror(UI_R_INDEX_TOO_LARGE); |
434 | return NULL; | 430 | return NULL; |
435 | } | 431 | } |
436 | return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); | 432 | return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); |
@@ -514,7 +510,7 @@ int | |||
514 | UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) | 510 | UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) |
515 | { | 511 | { |
516 | if (ui == NULL) { | 512 | if (ui == NULL) { |
517 | UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER); | 513 | UIerror(ERR_R_PASSED_NULL_PARAMETER); |
518 | return -1; | 514 | return -1; |
519 | } | 515 | } |
520 | switch (cmd) { | 516 | switch (cmd) { |
@@ -532,7 +528,7 @@ UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) | |||
532 | default: | 528 | default: |
533 | break; | 529 | break; |
534 | } | 530 | } |
535 | UIerr(UI_F_UI_CTRL, UI_R_UNKNOWN_CONTROL_COMMAND); | 531 | UIerror(UI_R_UNKNOWN_CONTROL_COMMAND); |
536 | return -1; | 532 | return -1; |
537 | } | 533 | } |
538 | 534 | ||
@@ -831,8 +827,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result) | |||
831 | case UIT_VERIFY: | 827 | case UIT_VERIFY: |
832 | if (l < uis->_.string_data.result_minsize) { | 828 | if (l < uis->_.string_data.result_minsize) { |
833 | ui->flags |= UI_FLAG_REDOABLE; | 829 | ui->flags |= UI_FLAG_REDOABLE; |
834 | UIerr(UI_F_UI_SET_RESULT, | 830 | UIerror(UI_R_RESULT_TOO_SMALL); |
835 | UI_R_RESULT_TOO_SMALL); | ||
836 | ERR_asprintf_error_data | 831 | ERR_asprintf_error_data |
837 | ("You must type in %d to %d characters", | 832 | ("You must type in %d to %d characters", |
838 | uis->_.string_data.result_minsize, | 833 | uis->_.string_data.result_minsize, |
@@ -841,8 +836,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result) | |||
841 | } | 836 | } |
842 | if (l > uis->_.string_data.result_maxsize) { | 837 | if (l > uis->_.string_data.result_maxsize) { |
843 | ui->flags |= UI_FLAG_REDOABLE; | 838 | ui->flags |= UI_FLAG_REDOABLE; |
844 | UIerr(UI_F_UI_SET_RESULT, | 839 | UIerror(UI_R_RESULT_TOO_LARGE); |
845 | UI_R_RESULT_TOO_LARGE); | ||
846 | ERR_asprintf_error_data | 840 | ERR_asprintf_error_data |
847 | ("You must type in %d to %d characters", | 841 | ("You must type in %d to %d characters", |
848 | uis->_.string_data.result_minsize, | 842 | uis->_.string_data.result_minsize, |
@@ -850,7 +844,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result) | |||
850 | return -1; | 844 | return -1; |
851 | } | 845 | } |
852 | if (!uis->result_buf) { | 846 | if (!uis->result_buf) { |
853 | UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER); | 847 | UIerror(UI_R_NO_RESULT_BUFFER); |
854 | return -1; | 848 | return -1; |
855 | } | 849 | } |
856 | strlcpy(uis->result_buf, result, | 850 | strlcpy(uis->result_buf, result, |
@@ -861,7 +855,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result) | |||
861 | const char *p; | 855 | const char *p; |
862 | 856 | ||
863 | if (!uis->result_buf) { | 857 | if (!uis->result_buf) { |
864 | UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER); | 858 | UIerror(UI_R_NO_RESULT_BUFFER); |
865 | return -1; | 859 | return -1; |
866 | } | 860 | } |
867 | uis->result_buf[0] = '\0'; | 861 | uis->result_buf[0] = '\0'; |