summaryrefslogtreecommitdiffstats
path: root/Lib/getpass.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-10-31 21:26:08 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2009-10-31 21:26:08 (GMT)
commit29b5365f6981523bb6a84e3eaf57f4d4433d27ae (patch)
tree2df2132b6d0195f99998adbebfc3039133ff4f2d /Lib/getpass.py
parentb2b92ea7bc9abcde3209414b21d80f699dff20bb (diff)
downloadcpython-29b5365f6981523bb6a84e3eaf57f4d4433d27ae.zip
cpython-29b5365f6981523bb6a84e3eaf57f4d4433d27ae.tar.gz
cpython-29b5365f6981523bb6a84e3eaf57f4d4433d27ae.tar.bz2
Fixes issue7208 - getpass would still allow the password to be echoed on
Solaris due to not flushing the input buffer. This change also incorporates some additional getpass implementation suggestions for security based on an analysis of getpass.c linked to from the issue.
Diffstat (limited to 'Lib/getpass.py')
-rw-r--r--Lib/getpass.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/getpass.py b/Lib/getpass.py
index 9a1273c..4745ea9 100644
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -62,12 +62,16 @@ def unix_getpass(prompt='Password: ', stream=None):
try:
old = termios.tcgetattr(fd) # a copy to save
new = old[:]
- new[3] &= ~termios.ECHO # 3 == 'lflags'
+ new[3] &= ~(termios.ECHO|termios.ISIG) # 3 == 'lflags'
+ tcsetattr_flags = termios.TCSAFLUSH
+ if hasattr(termios, 'TCSASOFT'):
+ tcsetattr_flags |= termios.TCSASOFT
try:
- termios.tcsetattr(fd, termios.TCSADRAIN, new)
+ termios.tcsetattr(fd, tcsetattr_flags, new)
passwd = _raw_input(prompt, stream, input=input)
finally:
- termios.tcsetattr(fd, termios.TCSADRAIN, old)
+ termios.tcsetattr(fd, tcsetattr_flags, old)
+ stream.flush() # issue7208
except termios.error, e:
if passwd is not None:
# _raw_input succeeded. The final tcsetattr failed. Reraise
@@ -125,6 +129,7 @@ def _raw_input(prompt="", stream=None, input=None):
if prompt:
stream.write(prompt)
stream.flush()
+ # NOTE: The Python C API calls flockfile() (and unlock) during readline.
line = input.readline()
if not line:
raise EOFError