[issue44762] getpass.getpass on Windows fallback detection is bad

2021-08-04 Thread Terry J. Reedy
Terry J. Reedy added the comment: The rationale for the __stdin__ and stdin check is this: When python starts, both are usually set an io.TextIOWrapper wrapping a system console. (At least on Windows, both may instead be None instead.) __stdin__ should never be altered. Getpass.getpass kn

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-29 Thread Eryk Sun
Eryk Sun added the comment: > WindowsConsoleIO doesn't actually use the standard file descriptors > for stdin/out/err To resolve bpo-30555, _WindowsConsoleIO was changed to eliminate self->handle and get the underlying handle dynamically via _get_osfhandle(). It's thus susceptible to close(

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-29 Thread Steve Dower
Steve Dower added the comment: > I suppose checking the file type in io._WindowsConsoleIO.isatty() could be > useful in case the file descriptor gets reassigned to a non-console file > (e.g. via os.close or os.dup2). Pretty sure we currently don't support these anyway. WindowsConsoleIO doesn

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-29 Thread Eryk Sun
Eryk Sun added the comment: > We could also provide a better check in WindowsConsoleIO.isatty, For isatty(), my concern is a false positive if the file is the "NUL" device, which should be an io.FileIO object. I suppose checking the file type in io._WindowsConsoleIO.isatty() could be useful

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-29 Thread Eryk Sun
Eryk Sun added the comment: It should be noted that changing win_getpass() to check sys.stdin.isatty() makes it inconsistent with unix_getpass(). The latter tries to open "/dev/tty" regardless of sys.stdin. To be consistent, win_getpass() would be implemented to call fallback_getpass() only

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread Steve Dower
Steve Dower added the comment: We could also provide a better check in WindowsConsoleIO.isatty, since that should have already handled most of the previous checks (I wouldn't want to do a typecheck in getpass, though). But yeah, this seems like "sys.stdin and sys.stdin.isatty()" is the right

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread Zachary Ware
Change by Zachary Ware : -- components: +Windows nosy: +paul.moore, steve.dower, tim.golden, zach.ware stage: -> needs patch versions: +Python 3.10, Python 3.11 ___ Python tracker ___

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread Eryk Sun
Eryk Sun added the comment: > When the check incorrectly infers that it can use `msvcrt` while > its stdin is a pipe, the calls to `putwch` and `getwch` are going > into the void and the program effectively freezes waiting for > input that never comes. The C runtime's getwch() and putwch()

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread jan matejek
Change by jan matejek : -- versions: +Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread jan matejek
Change by jan matejek : -- versions: -Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker ___

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread jan matejek
jan matejek added the comment: For that matter, in standard Windows Command Prompt `sys.stdin` and `sys.__stdin__` are also identical, but `isatty()` reports True. I suspect is that the code has drifted and `sys.stdin` is _always_ identical to `sys.__stdin__` ? -- _

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread jan matejek
jan matejek added the comment: ...this is a problem because: When the check incorrectly infers that it can use `msvcrt` while its stdin is a pipe, the calls to `putwch` and `getwch` are going into the void and the program effectively freezes waiting for input that never comes. See also: htt

[issue44762] getpass.getpass on Windows fallback detection is bad

2021-07-28 Thread jan matejek
New submission from jan matejek : The fallback detection for `win_getpass` checks that `sys.stdin` is different from `sys.__stdin__`. If yes, it assumes that it's incapable of disabling echo, and calls `default_getpass` which reads from stdin. If they are the same object, it assumes it's in a