Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-07-09 16:57:03 +0400
committerCorinna Vinschen <corinna@vinschen.de>2012-07-09 16:57:03 +0400
commit7c4626ed08b9e06e7c3a2d46b38b13827ec33955 (patch)
treee9ea4aff86adf534dfbf0755064e599da0516ac2 /winsup/cygwin
parent821c8b9aacac0dde42d6d9a957ca7534ae3fedfc (diff)
* passwd.cc (getpass): Make check for closed stream more reliable.
Check if setting tty attributes worked and only revert to old state if so.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog8
-rw-r--r--winsup/cygwin/passwd.cc19
2 files changed, 19 insertions, 8 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 604651f53..8b1f98e3e 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,4 +1,10 @@
-2012-07-08 Corinna Vinschen <corinna@vinschen.de>
+2012-07-09 Corinna Vinschen <corinna@vinschen.de>
+
+ * passwd.cc (getpass): Make check for closed stream more reliable.
+ Check if setting tty attributes worked and only revert to old state
+ if so.
+
+2012-07-09 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in, configure.in, mkvers.sh: Revert accidental checkin from
2012-07-06.
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index 6e012ed68..c6abb0205 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -281,6 +281,7 @@ getpass (const char * prompt)
{
char *pass = _my_tls.locals.pass;
struct termios ti, newti;
+ bool tc_set = false;
/* Try to use controlling tty in the first place. Use stdin and stderr
only as fallback. */
@@ -295,19 +296,23 @@ getpass (const char * prompt)
}
/* Make sure to notice if stdin is closed. */
- if (tcgetattr (fileno (in), &ti) == -1)
- pass[0] = '\0';
- else
+ if (fileno (in) >= 0)
{
flockfile (in);
- newti = ti;
- newti.c_lflag &= ~(ECHO | ISIG); /* No echo, no signal handling. */
- tcsetattr (fileno (in), TCSANOW, &newti);
+ /* Change tty attributes if possible. */
+ if (!tcgetattr (fileno (in), &ti))
+ {
+ newti = ti;
+ newti.c_lflag &= ~(ECHO | ISIG); /* No echo, no signal handling. */
+ if (!tcsetattr (fileno (in), TCSANOW, &newti))
+ tc_set = true;
+ }
fputs (prompt, err);
fflush (err);
fgets (pass, _PASSWORD_LEN, in);
fprintf (err, "\n");
- tcsetattr (fileno (in), TCSANOW, &ti);
+ if (tc_set)
+ tcsetattr (fileno (in), TCSANOW, &ti);
funlockfile (in);
char *crlf = strpbrk (pass, "\r\n");
if (crlf)