From a53ec4ac2de016e97d5ae4422c938ed7b3616a16 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Fri, 5 Apr 2019 19:10:38 -0700 Subject: [PATCH] termmode.go: Added nil check in term.Restore() for nonexistent cp filename Signed-off-by: Russ Magee --- hkexsh/hkexsh.go | 4 ++-- termmode_unix.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go index 366f0cb..ac7d0cc 100755 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -298,7 +298,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *hkexsh.S if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { exitStatus = uint32(status.ExitStatus()) fmt.Print(stdErrBuffer) - fmt.Printf("Exit Status: %d\n", exitStatus) //# + //fmt.Printf("Exit Status: %d\n", exitStatus) //# } } } @@ -367,7 +367,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *hkexsh.S // an ExitStatus() method with the same signature. if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { exitStatus = uint32(status.ExitStatus()) - log.Printf("Exit Status: %d", exitStatus) + //log.Printf("Exit Status: %d", exitStatus) } } } diff --git a/termmode_unix.go b/termmode_unix.go index 8bcb60a..e1b4cd1 100644 --- a/termmode_unix.go +++ b/termmode_unix.go @@ -3,6 +3,7 @@ package hkexsh import ( + "errors" "io" unix "golang.org/x/sys/unix" @@ -67,7 +68,11 @@ func GetState(fd int) (*State, error) { // Restore restores the terminal connected to the given file descriptor to a // previous state. func Restore(fd int, state *State) error { - return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios) + if state != nil { + return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios) + } else { + return errors.New("nil State") + } } // ReadPassword reads a line of input from a terminal without local echo. This