Skip to content

Commit

Permalink
Upgrade by replacement if executable is in temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 3, 2019
1 parent c56f61d commit c86e2ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,18 @@ func getMethod(fs vfs.FS, executableFilename string) (string, error) {
if err != nil {
return "", err
}
executableIsInTempDir, err := vfs.Contains(fs, executableFilename, os.TempDir())
if err != nil {
return "", err
}
executableStat := info.Sys().(*syscall.Stat_t)
uid := os.Getuid()
switch runtime.GOOS {
case "darwin":
if int(executableStat.Uid) != uid {
return "", fmt.Errorf("%s: cannot upgrade executable owned by non-current user", executableFilename)
}
if executableInUserHomeDir {
if executableInUserHomeDir || executableIsInTempDir {
return methodReplaceExecutable, nil
}
return methodUpgradePackage, nil
Expand All @@ -371,7 +375,7 @@ func getMethod(fs vfs.FS, executableFilename string) (string, error) {
if executableStat.Uid != 0 {
return "", fmt.Errorf("%s: cannot upgrade executable owned by non-root user when running as root", executableFilename)
}
if executableInUserHomeDir {
if executableInUserHomeDir || executableIsInTempDir {
return methodReplaceExecutable, nil
}
return methodUpgradePackage, nil
Expand Down

0 comments on commit c86e2ba

Please sign in to comment.