mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 23:40:28 -10:00
Using unqualified taskkill / taskkill.exe commands on Windows can allow binary hijacking under certain conditions. Update all process termination callers on Windows to resolve the absolute path to taskkill.exe under System32 (referencing SystemRoot/windir environment variables, falling back to C:\Windows).
33 lines
611 B
Go
33 lines
611 B
Go
//go:build windows
|
|
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strconv"
|
|
)
|
|
|
|
func configureCommandProcess(cmd *exec.Cmd) {}
|
|
|
|
func terminateCommandProcess(cmd *exec.Cmd) {
|
|
if cmd.Process == nil {
|
|
return
|
|
}
|
|
taskkill := taskkillPath()
|
|
_ = exec.Command(taskkill, "/T", "/F", "/PID", strconv.Itoa(cmd.Process.Pid)).Run()
|
|
_ = cmd.Process.Kill()
|
|
}
|
|
|
|
func taskkillPath() string {
|
|
systemRoot := os.Getenv("SystemRoot")
|
|
if systemRoot == "" {
|
|
systemRoot = os.Getenv("windir")
|
|
}
|
|
if systemRoot == "" {
|
|
systemRoot = `C:\Windows`
|
|
}
|
|
return filepath.Join(systemRoot, "System32", "taskkill.exe")
|
|
}
|