mirror of
https://github.com/golang/term.git
synced 2026-01-29 15:12:09 +03:00
ssh/terminal: use duplicate handle in ReadPassword
os.NewFile assigns finalizer to close file handle passed into ReadPassword. But that is not expected. Make a duplicate of original file handle, and pass copy handle into ReadPassword instead. Fixes golang/go#23525 Change-Id: I4d6725e9a1cc20defd1b58afc383e35a7f9ee4e9 Reviewed-on: https://go-review.googlesource.com/89395 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Alex Brainman
parent
f344d0325d
commit
189f313d0c
@@ -93,5 +93,13 @@ func ReadPassword(fd int) ([]byte, error) {
|
||||
windows.SetConsoleMode(windows.Handle(fd), old)
|
||||
}()
|
||||
|
||||
return readPasswordLine(os.NewFile(uintptr(fd), "stdin"))
|
||||
var h windows.Handle
|
||||
p, _ := windows.GetCurrentProcess()
|
||||
if err := windows.DuplicateHandle(p, windows.Handle(fd), p, &h, 0, false, windows.DUPLICATE_SAME_ACCESS); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f := os.NewFile(uintptr(h), "stdin")
|
||||
defer f.Close()
|
||||
return readPasswordLine(f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user