New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/crypto/ssh/terminal: ReadPassword reads a maximum of 254 chars on Windows #36071
Comments
/cc @FiloSottile @katiehockman @alexbrainman As you mentioned, this does look to be windows specific. I was not able to reproduce this on Linux. |
@ncw @alexbrainman https://docs.microsoft.com/en-us/dotnet/api/system.console.readline?view=netframework-4.8
From what I am seeing here, it's pointing to that: In case the same API is used, that may explain what's happening |
It is limit of ENABLE_LINE_INPUT. When using ReadConsole with ENABLE_LINE_INPUT, the input buffer always be 254 (256 - \r - \n). To solve this issue, ReadPassword stop to use ENABLE_LINE_INPUT. diff --git a/ssh/terminal/terminal.go b/ssh/terminal/terminal.go
index 2f04ee5..ea2cd57 100644
--- a/ssh/terminal/terminal.go
+++ b/ssh/terminal/terminal.go
@@ -946,11 +946,17 @@ func readPasswordLine(reader io.Reader) ([]byte, error) {
for {
n, err := reader.Read(buf[:])
if n > 0 {
- switch buf[0] {
+ switch byte(buf[0]) {
+ case '\b':
+ if len(ret) > 0 {
+ ret = ret[:len(ret)-1]
+ }
case '\n':
return ret, nil
case '\r':
- // remove \r from passwords on Windows
+ // On Windows, \n never read when ENABLE_LINE_INPUT is
+ // disabled.
+ return ret, nil
default:
ret = append(ret, buf[0])
}
diff --git a/ssh/terminal/util_windows.go b/ssh/terminal/util_windows.go
index 5cfdf8f..c2cdf24 100644
--- a/ssh/terminal/util_windows.go
+++ b/ssh/terminal/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 | windows.ENABLE_PROCESSED_INPUT)
+ st |= windows.ENABLE_PROCESSED_OUTPUT
if err := windows.SetConsoleMode(windows.Handle(fd), st); err != nil {
return nil, err
} |
Sorry, the code above is wrong. we must stop to use ENABLE_PROCESSED_INPUT too. |
For the note: dotnet/corefx@f374612 |
Change https://golang.org/cl/212377 mentions this issue: |
I merged this fix into rclone however @Ajaja reported in rclone/rclone#3888 that the Enter key no longer works. I can confirm this, the little test program above fails on WIndows 10 - you can't press Enter to end the input. Sorry, I missed the new issue about this #36609 |
Sorry for submitting completely broken version.
Yes. The fix https://go-review.googlesource.com/c/crypto/+/215417 is out for review. Alex |
Currently we are using simple Input to read token. Due to some limitation adn echoing it will be better to read it as password. > ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is enabled. Refs: golang/go#36071
Currently we are using simple Input to read token. Due to some limitation adn echoing it will be better to read it as password. > ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is enabled. Refs: golang/go#36071
Currently we are using simple Input to read token. Due to some limitation adn echoing it will be better to read it as password. > ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is enabled. Refs: golang/go#36071
Currently we are using simple Input to read token. Due to some limitation adn echoing it will be better to read it as password. > ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is enabled. Refs: golang/go#36071
Currently we are using simple Input to read token. Due to some limitation adn echoing it will be better to read it as password. > ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is enabled. Refs: golang/go#36071
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 <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
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 <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
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 <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
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 <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
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 <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
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 <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes (not tried tip)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran this program and typed > 254 characters
What did you expect to see?
I expected to see all the characters I typed or an error message
What did you see instead?
My input string silently truncated to the first 254 characters.
The text was updated successfully, but these errors were encountered: