summaryrefslogtreecommitdiff
path: root/src/tool_getpass.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2015-02-03 00:30:45 +0100
committerDaniel Stenberg <daniel@haxx.se>2015-02-03 00:30:45 +0100
commit859a82a85cc0a1ea6dff496b3542beda0b06f933 (patch)
tree34107f67bc124e9f0f2329924774355256c81263 /src/tool_getpass.c
parent8f369c53cf0bb94d9ef939153d6da51b364894ea (diff)
downloadgnurl-859a82a85cc0a1ea6dff496b3542beda0b06f933.tar.gz
gnurl-859a82a85cc0a1ea6dff496b3542beda0b06f933.tar.bz2
gnurl-859a82a85cc0a1ea6dff496b3542beda0b06f933.zip
getpass_r: read from stdin, not stdout!
The file number used was wrong. This bug was introduced over 10 years ago, proving this function isn't used much... Bug: http://curl.haxx.se/bug/view.cgi?id=1476 Reported-by: Tamir
Diffstat (limited to 'src/tool_getpass.c')
-rw-r--r--src/tool_getpass.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/tool_getpass.c b/src/tool_getpass.c
index 4c8dcb9f1..34e0e6f5b 100644
--- a/src/tool_getpass.c
+++ b/src/tool_getpass.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -52,6 +52,7 @@
# endif
#endif
+#include <unistd.h>
#define _MPRINTF_REPLACE
#include <curl/mprintf.h>
@@ -229,7 +230,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
bool disabled;
int fd = open("/dev/tty", O_RDONLY);
if(-1 == fd)
- fd = 1; /* use stdin if the tty couldn't be used */
+ fd = STDIN_FILENO; /* use stdin if the tty couldn't be used */
disabled = ttyecho(FALSE, fd); /* disable terminal echo */
@@ -246,7 +247,7 @@ char *getpass_r(const char *prompt, /* prompt to display */
(void)ttyecho(TRUE, fd); /* enable echo */
}
- if(1 != fd)
+ if(STDIN_FILENO != fd)
close(fd);
return password; /* return pointer to buffer */