Skip to content

Commit

Permalink
all: backport Go 1.19 os/exec behavior changes via execabs
Browse files Browse the repository at this point in the history
This is probably overly conservative since this behavior doesn't affect
Mutagen to the extent that it affects the Go toolchain commands, but
it's an easy fix to make and shouldn't have any adverse effect on
Mutagen users.

For more background information, see https://go.dev/blog/path-security
and https://go.dev/doc/go1.19.

Signed-off-by: Jacob Howard <jacob@mutagen.io>
  • Loading branch information
xenoscopic committed Aug 8, 2022
1 parent e33eabd commit cacfc18
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cmd/mutagen/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/exec"
"runtime"

"golang.org/x/sys/execabs"

"github.com/spf13/cobra"

"github.com/mutagen-io/mutagen/cmd"
Expand All @@ -31,7 +33,7 @@ func startMain(_ *cobra.Command, _ []string) error {
if !external.UsePathBasedLookupForDaemonStart {
executablePath, err = os.Executable()
} else {
executablePath, err = exec.LookPath(process.ExecutableName("mutagen", runtime.GOOS))
executablePath, err = execabs.LookPath(process.ExecutableName("mutagen", runtime.GOOS))
}
if err != nil {
return fmt.Errorf("unable to determine executable path: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion cmd/terminal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"os/exec"

"golang.org/x/sys/execabs"

isatty "github.com/mattn/go-isatty"
)

Expand All @@ -22,7 +24,7 @@ func HandleTerminalCompatibility() {

// Since we're running inside a mintty-based terminal, we need to relaunch
// using winpty, so first attempt to locate it.
winpty, err := exec.LookPath("winpty")
winpty, err := execabs.LookPath("winpty")
if err != nil {
Fatal(errors.New("running inside mintty terminal and unable to locate winpty"))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/docker/docker_darwin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package docker

import (
"os/exec"
"golang.org/x/sys/execabs"

"github.com/mutagen-io/mutagen/pkg/process"
)
Expand All @@ -17,7 +17,7 @@ var commandSearchPaths = []string{
func commandPathForPlatform() (string, error) {
// First, attempt to find the docker executable using the PATH environment
// variable. If that works, use that result.
if path, err := exec.LookPath("docker"); err == nil {
if path, err := execabs.LookPath("docker"); err == nil {
return path, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/docker/docker_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
package docker

import (
"os/exec"
"golang.org/x/sys/execabs"
)

// commandPathForPlatform searches for the docker command in the user's path.
func commandPathForPlatform() (string, error) {
return exec.LookPath("docker")
return execabs.LookPath("docker")
}
4 changes: 2 additions & 2 deletions pkg/docker/docker_windows.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package docker

import (
"os/exec"
"golang.org/x/sys/execabs"
)

// commandPathForPlatform searches for the docker command in the user's path.
func commandPathForPlatform() (string, error) {
return exec.LookPath("docker")
return execabs.LookPath("docker")
}
6 changes: 3 additions & 3 deletions pkg/ssh/ssh_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
package ssh

import (
"os/exec"
"golang.org/x/sys/execabs"
)

// sshCommandPathForPlatform searches for the ssh command in the user's path.
func sshCommandPathForPlatform() (string, error) {
return exec.LookPath("ssh")
return execabs.LookPath("ssh")
}

// scpCommandPathForPlatform searches for the scp command in the user's path.
func scpCommandPathForPlatform() (string, error) {
return exec.LookPath("scp")
return execabs.LookPath("scp")
}

0 comments on commit cacfc18

Please sign in to comment.