1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-02 14:22:51 +03:00

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.
This commit is contained in:
Vladislav Vaintroub
2013-03-26 08:17:22 +01:00
parent c579bce349
commit bfac7d637f

View File

@ -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");
}