Skip to content

Commit

Permalink
ssh/terminal: stop using ENABLE_LINE_INPUT
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mattn authored and alexbrainman committed Jan 15, 2020
1 parent 61a8779 commit 6d4e4cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ssh/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions ssh/terminal/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

3 comments on commit 6d4e4cb

@johmue
Copy link

@johmue johmue commented on 6d4e4cb Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the change of util_windows.go broke my builds. With this change the CLI will ignore the [RETURN]-Key. Below the code for testing:

package main

import (
    "log"
    "syscall"
    "golang.org/x/crypto/ssh/terminal"
)

func main() {
	log.Print("Your user password: ")
	bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
	if err != nil {
		log.Fatalf("unable to read password from cli")
	}
	password := string(bytePassword)
	log.Print(password)
}

tested with WIN 10 / Vers. 1809 / Build 17763.914 / go 1.13.6

@toothrot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the change of util_windows.go broke my builds. With this change the CLI will ignore the [RETURN]-Key. Below the code for testing:

package main

import (
    "log"
    "syscall"
    "golang.org/x/crypto/ssh/terminal"
)

func main() {
	log.Print("Your user password: ")
	bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
	if err != nil {
		log.Fatalf("unable to read password from cli")
	}
	password := string(bytePassword)
	log.Print(password)
}

tested with WIN 10 / Vers. 1809 / Build 17763.914 / go 1.13.6

@johmue Would you mind filing an issue for this?

@johmue
Copy link

@johmue johmue commented on 6d4e4cb Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, see golang/go#36609

Please sign in to comment.