Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5046788

Browse files
committed
Merged revisions 76000,76016 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r76000 | gregory.p.smith | 2009-10-31 14:26:08 -0700 (Sat, 31 Oct 2009) | 7 lines 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. ........ r76016 | gregory.p.smith | 2009-11-01 10:33:55 -0800 (Sun, 01 Nov 2009) | 2 lines news entry for r76000 ........
1 parent f3b8002 commit 5046788

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/getpass.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ def unix_getpass(prompt='Password: ', stream=None):
6262
try:
6363
old = termios.tcgetattr(fd) # a copy to save
6464
new = old[:]
65-
new[3] &= ~termios.ECHO # 3 == 'lflags'
65+
new[3] &= ~(termios.ECHO|termios.ISIG) # 3 == 'lflags'
66+
tcsetattr_flags = termios.TCSAFLUSH
67+
if hasattr(termios, 'TCSASOFT'):
68+
tcsetattr_flags |= termios.TCSASOFT
6669
try:
67-
termios.tcsetattr(fd, termios.TCSADRAIN, new)
70+
termios.tcsetattr(fd, tcsetattr_flags, new)
6871
passwd = _raw_input(prompt, stream, input=input)
6972
finally:
70-
termios.tcsetattr(fd, termios.TCSADRAIN, old)
73+
termios.tcsetattr(fd, tcsetattr_flags, old)
74+
stream.flush() # issue7208
7175
except termios.error as e:
7276
if passwd is not None:
7377
# _raw_input succeeded. The final tcsetattr failed. Reraise
@@ -124,6 +128,7 @@ def _raw_input(prompt="", stream=None, input=None):
124128
if prompt:
125129
stream.write(prompt)
126130
stream.flush()
131+
# NOTE: The Python C API calls flockfile() (and unlock) during readline.
127132
line = input.readline()
128133
if not line:
129134
raise EOFError

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ C-API
120120
Library
121121
-------
122122

123+
- Issue #7246 & Issue #7208: getpass now properly flushes input before
124+
reading from stdin so that existing input does not confuse it and
125+
lead to incorrect entry or an IOError. It also properly flushes it
126+
afterwards to avoid the terminal echoing the input afterwards on
127+
OSes such as Solaris.
128+
123129
- Issue #7233: Fix a number of two-argument Decimal methods to make
124130
sure that they accept an int or long as the second argument. Also
125131
fix buggy handling of large arguments (those with coefficient longer

0 commit comments

Comments
 (0)