From 0258724bd8c88dcfeab79c061d479c564472f113 Mon Sep 17 00:00:00 2001 From: Gregor Pogacnik <1640719+fiksn@users.noreply.github.com> Date: Thu, 13 Aug 2020 18:57:11 +0200 Subject: [PATCH] Fix #22 - search for stty in PATH --- speakeasy_unix.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/speakeasy_unix.go b/speakeasy_unix.go index d99fda1..353034c 100644 --- a/speakeasy_unix.go +++ b/speakeasy_unix.go @@ -11,12 +11,13 @@ package speakeasy import ( "fmt" "os" + "os/exec" "os/signal" "strings" "syscall" ) -const sttyArg0 = "/bin/stty" +const sttyBin = "stty" var ( sttyArgvEOff = []string{"stty", "-echo"} @@ -64,7 +65,11 @@ func getPassword() (password string, err error) { // echoOff turns off the terminal echo. func echoOff(fd []uintptr) (int, error) { - pid, err := syscall.ForkExec(sttyArg0, sttyArgvEOff, &syscall.ProcAttr{Dir: "", Files: fd}) + path, err := exec.LookPath(sttyBin) + if err != nil { + return 0, fmt.Errorf("%s binary not found:\n\t%s", sttyBin, err) + } + pid, err := syscall.ForkExec(path, sttyArgvEOff, &syscall.ProcAttr{Dir: "", Files: fd}) if err != nil { return 0, fmt.Errorf("failed turning off console echo for password entry:\n\t%s", err) } @@ -74,7 +79,11 @@ func echoOff(fd []uintptr) (int, error) { // echoOn turns back on the terminal echo. func echoOn(fd []uintptr) { // Turn on the terminal echo. - pid, e := syscall.ForkExec(sttyArg0, sttyArgvEOn, &syscall.ProcAttr{Dir: "", Files: fd}) + path, err := exec.LookPath(sttyBin) + if err != nil { + return + } + pid, e := syscall.ForkExec(path, sttyArgvEOn, &syscall.ProcAttr{Dir: "", Files: fd}) if e == nil { syscall.Wait4(pid, nil, 0, nil) }