Only sucessfully replicated on solaris. When running getpass() - it goes into non echo mode, however, once enter is pressed, the password is echoed to the screen. E.g. > /opt/python/2.6.3/bin/python -c 'import getpass; x=getpass.getpass()' Password: bob This does NOT happen on older versions: > /opt/IBpython/2.5.1/bin/python -c 'import getpass; x=getpass.getpass()' Password: /opt/python/2.3.3/bin/python -c 'import getpass; x=getpass.getpass()' Password: To stop this occuring for me, simply adding a stream.flush() line straight after the finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) line fixes the issue: saundep@ln8u3494inx:[/tmp]> /opt/IBpython/2.6.3/bin/python -c 'import gp; gp.getpass()' Password:
Regarding your comment in r76000: """NOTE: The Python C API calls flockfile() (and unlock) during readline.""" This may be true in 2.x but not in 3.x. Does it have any security implication?
It might mean that other threads with access to the same file handle could interfere and intercept part of the password entry if they wanted to but thats not too concerning. py3k/Modules/_io/bufferedio.c which is presumably used when input is sys.stdin instead of a /dev/tty file appears to lock things. Compared to glibc's getpass implementation the locking should probably be done around a wider swath of getpass code in order to protect all possible race conditions of other code accessing the handle as we set it up and display the prompt. I don't really think it is something worry about as it requires code executing within the context of your own getpass calling program to be doing something that'll interfere with your password reading. If someone has -that- problem they have bigger issues.