From bfac7d637f0118481b0aa35ebd1d9711b90baadc Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 26 Mar 2013 08:17:22 +0100 Subject: MDEV-4330 - get_tty_password() does not work if input redirection is used. The reason is the limitation of ReadConsole() API, it returns error if handle to redirected input is used. The fix is to use a handle returned by CreateFile("CONIN$",...), rather than GetStdHandle(STD_HANDLE_INPUT) to get the true console handle. --- libmysql/get_password.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libmysql/get_password.c b/libmysql/get_password.c index e65bd6de2f6..ffb08c46aa1 100644 --- a/libmysql/get_password.c +++ b/libmysql/get_password.c @@ -67,8 +67,8 @@ void get_tty_password_buff(const char *opt_message, char *to, size_t length) char *pos=to,*end=to+length-1; int i=0; - consoleinput= GetStdHandle(STD_INPUT_HANDLE); - if (!consoleinput) + consoleinput= CreateFile("CONIN$", GENERIC_WRITE | GENERIC_READ, 0 , NULL, 0, 0, NULL); + if (consoleinput == NULL || consoleinput == INVALID_HANDLE_VALUE) { /* This is a GUI application or service without console input, bail out. */ *to= 0; @@ -108,6 +108,7 @@ void get_tty_password_buff(const char *opt_message, char *to, size_t length) } /* Reset console mode after password input. */ SetConsoleMode(consoleinput, oldstate); + CloseHandle(consoleinput); *pos=0; _cputs("\n"); } -- cgit v1.2.1