X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Fui%2Fui_openssl.c;h=78b88c07f1078e114421fa25fa4019d862ded399;hb=HEAD;hp=cf873431f7a014a6d5fe464f707cb8874328174c;hpb=706457b7bda7fdbab426b8dce83b318908339da4;p=openssl.git diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c index cf873431f7..544415e5b1 100644 --- a/crypto/ui/ui_openssl.c +++ b/crypto/ui/ui_openssl.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,7 +7,7 @@ * https://www.openssl.org/source/license.html */ -#include "e_os.h" +#include "internal/e_os.h" #include #include #include @@ -127,7 +127,7 @@ # define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) # endif -# if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) +# if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && ! (defined(OPENSSL_SYS_TANDEM) && defined(_SPT_MODEL_)) # include # endif @@ -372,7 +372,8 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) /* Internal functions to open, handle and close a channel to the console. */ static int open_console(UI *ui) { - CRYPTO_THREAD_write_lock(ui->lock); + if (!CRYPTO_THREAD_write_lock(ui->lock)) + return 0; is_a_tty = 1; # if defined(OPENSSL_SYS_VXWORKS) @@ -435,21 +436,28 @@ static int open_console(UI *ui) is_a_tty = 0; else # endif +# ifdef EPERM + /* + * Linux can return EPERM (Operation not permitted), + * e.g. if a daemon executes openssl via fork()+execve() + * This should be ok + */ + if (errno == EPERM) + is_a_tty = 0; + else +# endif # ifdef ENODEV /* * MacOS X returns ENODEV (Operation not supported by device), * 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); - UIerr(UI_F_OPEN_CONSOLE, 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; } } @@ -459,11 +467,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); - UIerr(UI_F_OPEN_CONSOLE, 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; } @@ -496,15 +501,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); - UIerr(UI_F_NOECHO_CONSOLE, 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; } } @@ -534,15 +533,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); - UIerr(UI_F_ECHO_CONSOLE, 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; } } @@ -558,6 +551,8 @@ static int echo_console(UI *ui) static int close_console(UI *ui) { + int ret = 1; + if (tty_in != stdin) fclose(tty_in); if (tty_out != stderr) @@ -565,17 +560,14 @@ 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); - UIerr(UI_F_CLOSE_CONSOLE, UI_R_SYSDASSGN_ERROR); - ERR_add_error_data(2, "status=", tmp_num); - return 0; + ERR_raise_data(ERR_LIB_UI, UI_R_SYSDASSGN_ERROR, + "status=%%X%08X", status); + ret = 0; } # endif CRYPTO_THREAD_unlock(ui->lock); - return 1; + return ret; } # if !defined(OPENSSL_SYS_WINCE)