Commit 3c1125d4 authored by Sergei Golubchik's avatar Sergei Golubchik

fixes for get_password():

1. on windows: don't hang when there's no console, that is, _getch() returns -1. 
2. on windows: _getch() returns an int, not char.
   to distinguish between (char)255 and (int)-1
3. everywhere. isspace(pos[-1]) == ' ' never worked,
   isspace() returns a boolean, not a char. the never-worked loop was
   removed to preserve the existing behavior.
parent b8b7b4eb
...@@ -82,9 +82,9 @@ void get_tty_password_buff(const char *opt_message, char *to, size_t length) ...@@ -82,9 +82,9 @@ void get_tty_password_buff(const char *opt_message, char *to, size_t length)
_cputs(opt_message ? opt_message : "Enter password: "); _cputs(opt_message ? opt_message : "Enter password: ");
for (;;) for (;;)
{ {
char tmp; int tmp;
tmp=_getch(); tmp=_getch();
if (tmp == '\b' || (int) tmp == 127) if (tmp == '\b' || tmp == 127)
{ {
if (pos != to) if (pos != to)
{ {
...@@ -93,15 +93,13 @@ void get_tty_password_buff(const char *opt_message, char *to, size_t length) ...@@ -93,15 +93,13 @@ void get_tty_password_buff(const char *opt_message, char *to, size_t length)
continue; continue;
} }
} }
if (tmp == '\n' || tmp == '\r' || tmp == 3) if (tmp == -1 || tmp == '\n' || tmp == '\r' || tmp == 3)
break; break;
if (iscntrl(tmp) || pos == end) if (iscntrl(tmp) || pos == end)
continue; continue;
_cputs("*"); _cputs("*");
*(pos++) = tmp; *(pos++) = (char)tmp;
} }
while (pos != to && isspace(pos[-1]) == ' ')
pos--; /* Allow dummy space at end */
*pos=0; *pos=0;
_cputs("\n"); _cputs("\n");
} }
...@@ -148,8 +146,6 @@ static void get_password(char *to,uint length,int fd, my_bool echo) ...@@ -148,8 +146,6 @@ static void get_password(char *to,uint length,int fd, my_bool echo)
} }
*(pos++) = tmp; *(pos++) = tmp;
} }
while (pos != to && isspace(pos[-1]) == ' ')
pos--; /* Allow dummy space at end */
*pos=0; *pos=0;
return; return;
} }
......
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