From 31072773c25ce9b9eb7231098dcb16f0f2b6bd09 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 22 Dec 2019 03:38:13 +0900 Subject: [PATCH] ssh/terminal: stop using ENABLE_LINE_INPUT ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is enabled. Fixes golang/go#36071 Change-Id: If5c160404b855387a80f1d57638aac3f2db1a097 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/212377 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- terminal.go | 4 ++++ util_windows.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/terminal.go b/terminal.go index 2f04ee5..dd7378c 100644 --- a/terminal.go +++ b/terminal.go @@ -947,6 +947,10 @@ func readPasswordLine(reader io.Reader) ([]byte, error) { n, err := reader.Read(buf[:]) if n > 0 { switch buf[0] { + case '\b': + if len(ret) > 0 { + ret = ret[:len(ret)-1] + } case '\n': return ret, nil case '\r': diff --git a/util_windows.go b/util_windows.go index 5cfdf8f..f614e9c 100644 --- a/util_windows.go +++ b/util_windows.go @@ -85,8 +85,8 @@ func ReadPassword(fd int) ([]byte, error) { } old := st - st &^= (windows.ENABLE_ECHO_INPUT) - st |= (windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT | windows.ENABLE_PROCESSED_OUTPUT) + st &^= (windows.ENABLE_ECHO_INPUT | windows.ENABLE_LINE_INPUT) + st |= (windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_PROCESSED_INPUT) if err := windows.SetConsoleMode(windows.Handle(fd), st); err != nil { return nil, err }