Commit bfac7d63 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

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.
parent c579bce3
......@@ -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");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment