diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2013-03-26 08:17:22 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2013-03-26 08:17:22 +0100 |
commit | bfac7d637f0118481b0aa35ebd1d9711b90baadc (patch) | |
tree | 9d31641797a8279691deb0922951ff9dd7ad0db2 | |
parent | c579bce3497bdf700b19bfe50a75e641330646d3 (diff) | |
download | mariadb-git-bfac7d637f0118481b0aa35ebd1d9711b90baadc.tar.gz |
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.
-rw-r--r-- | libmysql/get_password.c | 5 |
1 files 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"); } |