Skip to content

Commit

Permalink
x/crypto/ssh/terminal: ensure windows MakeRaw returns previous state
Browse files Browse the repository at this point in the history
The MakeRaw method should be returning the original state so that
it can be restored.  However, the current implementation is returning
the new, "raw" state.

Fixes golang/go#15155

Change-Id: I8e0b87229b7577544e1118fa4b95664d3a9cf5da
Reviewed-on: https://go-review.googlesource.com/21612
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
johnSchnake authored and bradfitz committed Apr 8, 2016
1 parent 6506e2c commit e327b30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions ssh/terminal/terminal_test.go
Expand Up @@ -6,6 +6,7 @@ package terminal

import (
"io"
"os"
"testing"
)

Expand Down Expand Up @@ -267,3 +268,24 @@ func TestTerminalSetSize(t *testing.T) {
}
}
}

func TestMakeRawState(t *testing.T) {
fd := int(os.Stdout.Fd())
if !IsTerminal(fd) {
t.Skip("stdout is not a terminal; skipping test")
}

st, err := GetState(fd)
if err != nil {
t.Fatalf("failed to get terminal state from GetState: %s", err)
}
defer Restore(fd, st)
raw, err := MakeRaw(fd)
if err != nil {
t.Fatalf("failed to get terminal state from MakeRaw: %s", err)
}

if *st != *raw {
t.Errorf("states do not match; was %v, expected %v", raw, st)
}
}
4 changes: 2 additions & 2 deletions ssh/terminal/util_windows.go
Expand Up @@ -87,8 +87,8 @@ func MakeRaw(fd int) (*State, error) {
if e != 0 {
return nil, error(e)
}
st &^= (enableEchoInput | enableProcessedInput | enableLineInput | enableProcessedOutput)
_, _, e = syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(fd), uintptr(st), 0)
raw := st &^ (enableEchoInput | enableProcessedInput | enableLineInput | enableProcessedOutput)
_, _, e = syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(fd), uintptr(raw), 0)
if e != 0 {
return nil, error(e)
}
Expand Down

0 comments on commit e327b30

Please sign in to comment.