diff options
author | Richard Levitte <levitte@openssl.org> | 2020-11-04 16:14:00 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-11-13 09:35:31 +0100 |
commit | a150f8e1fcc38752fef4d7c75d765d8efc7d46d6 (patch) | |
tree | f7f62c9a5d8407d8b17820fbef67378aa7b9ddbb /crypto/ui | |
parent | 9311d0c471ca2eaa259e8c1bbbeb7c46394c7ba2 (diff) |
CRYPTO: refactor ERR_raise()+ERR_add_error_data() to ERR_raise_data()
This is not done absolutely everywhere, as there are places where
the use of ERR_add_error_data() is quite complex, but at least the
simple cases are done.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13318)
Diffstat (limited to 'crypto/ui')
-rw-r--r-- | crypto/ui/ui_lib.c | 44 | ||||
-rw-r--r-- | crypto/ui/ui_openssl.c | 47 |
2 files changed, 30 insertions, 61 deletions
diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index 4c74546612..fd03dc6cd0 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -540,10 +540,8 @@ int UI_process(UI *ui) ok = -1; } - if (ok == -1) { - ERR_raise(ERR_LIB_UI, UI_R_PROCESSING_ERROR); - ERR_add_error_data(2, "while ", state); - } + if (ok == -1) + ERR_raise_data(ERR_LIB_UI, UI_R_PROCESSING_ERROR, "while %s", state); return ok; } @@ -881,29 +879,21 @@ int UI_set_result_ex(UI *ui, UI_STRING *uis, const char *result, int len) switch (uis->type) { case UIT_PROMPT: case UIT_VERIFY: - { - char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize) + 1]; - char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize) + 1]; - - BIO_snprintf(number1, sizeof(number1), "%d", - uis->_.string_data.result_minsize); - BIO_snprintf(number2, sizeof(number2), "%d", - uis->_.string_data.result_maxsize); - - if (len < uis->_.string_data.result_minsize) { - ui->flags |= UI_FLAG_REDOABLE; - ERR_raise(ERR_LIB_UI, UI_R_RESULT_TOO_SMALL); - ERR_add_error_data(5, "You must type in ", - number1, " to ", number2, " characters"); - return -1; - } - if (len > uis->_.string_data.result_maxsize) { - ui->flags |= UI_FLAG_REDOABLE; - ERR_raise(ERR_LIB_UI, UI_R_RESULT_TOO_LARGE); - ERR_add_error_data(5, "You must type in ", - number1, " to ", number2, " characters"); - return -1; - } + if (len < uis->_.string_data.result_minsize) { + ui->flags |= UI_FLAG_REDOABLE; + ERR_raise_data(ERR_LIB_UI, UI_R_RESULT_TOO_SMALL, + "You must type in %d to %d characters", + uis->_.string_data.result_minsize, + uis->_.string_data.result_maxsize); + return -1; + } + if (len > uis->_.string_data.result_maxsize) { + ui->flags |= UI_FLAG_REDOABLE; + ERR_raise_data(ERR_LIB_UI, UI_R_RESULT_TOO_LARGE, + "You must type in %d to %d characters", + uis->_.string_data.result_minsize, + uis->_.string_data.result_maxsize); + return -1; } if (uis->result_buf == NULL) { diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c index dc7e9cc56a..0a38658c72 100644 --- a/crypto/ui/ui_openssl.c +++ b/crypto/ui/ui_openssl.c @@ -451,15 +451,12 @@ static int open_console(UI *ui) * which seems appropriate. */ if (errno == ENODEV) - is_a_tty = 0; + is_a_tty = 0; else # endif { - char tmp_num[10]; - BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%d", errno); - ERR_raise(ERR_LIB_UI, UI_R_UNKNOWN_TTYGET_ERRNO_VALUE); - ERR_add_error_data(2, "errno=", tmp_num); - + ERR_raise_data(ERR_LIB_UI, UI_R_UNKNOWN_TTYGET_ERRNO_VALUE, + "errno=%d", errno); return 0; } } @@ -469,11 +466,8 @@ static int open_console(UI *ui) /* if there isn't a TT device, something is very wrong */ if (status != SS$_NORMAL) { - char tmp_num[12]; - - BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status); - ERR_raise(ERR_LIB_UI, UI_R_SYSASSIGN_ERROR); - ERR_add_error_data(2, "status=", tmp_num); + ERR_raise_data(ERR_LIB_UI, UI_R_SYSASSIGN_ERROR, + "status=%%X%08X", status); return 0; } @@ -506,15 +500,9 @@ static int noecho_console(UI *ui) status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12, 0, 0, 0, 0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) { - char tmp_num[2][12]; - - BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X", - status); - BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X", - iosb.iosb$w_value); - ERR_raise(ERR_LIB_UI, UI_R_SYSQIOW_ERROR); - ERR_add_error_data(5, "status=", tmp_num[0], - ",", "iosb.iosb$w_value=", tmp_num[1]); + ERR_raise_data(ERR_LIB_UI, UI_R_SYSQIOW_ERROR, + "status=%%X%08X, iosb.iosb$w_value=%%X%08X", + status, iosb.iosb$w_value); return 0; } } @@ -544,15 +532,9 @@ static int echo_console(UI *ui) status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12, 0, 0, 0, 0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) { - char tmp_num[2][12]; - - BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X", - status); - BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X", - iosb.iosb$w_value); - ERR_raise(ERR_LIB_UI, UI_R_SYSQIOW_ERROR); - ERR_add_error_data(5, "status=", tmp_num[0], - ",", "iosb.iosb$w_value=", tmp_num[1]); + ERR_raise_data(ERR_LIB_UI, UI_R_SYSQIOW_ERROR, + "status=%%X%08X, iosb.iosb$w_value=%%X%08X", + status, iosb.iosb$w_value); return 0; } } @@ -575,11 +557,8 @@ static int close_console(UI *ui) # ifdef OPENSSL_SYS_VMS status = sys$dassgn(channel); if (status != SS$_NORMAL) { - char tmp_num[12]; - - BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status); - ERR_raise(ERR_LIB_UI, UI_R_SYSDASSGN_ERROR); - ERR_add_error_data(2, "status=", tmp_num); + ERR_raise_data(ERR_LIB_UI, UI_R_SYSDASSGN_ERROR, + "status=%%X%08X", status); return 0; } # endif |