WindowsCmdExe returns the absolute path to cmd.exe on Windows using the SystemRoot environment variable (e.g. C:\Windows\System32\cmd.exe). This avoids resolving cmd.exe through PATH, which would be vulnerable to untrusted search path attacks (CWE-426). If the ComSpec environment variable is set, i
()
| 20 | // As a last resort, if neither ComSpec nor SystemRoot is set, it falls back |
| 21 | // to the bare "cmd.exe" name (should never happen on a normal Windows system). |
| 22 | func WindowsCmdExe() string { |
| 23 | if comspec := os.Getenv("ComSpec"); comspec != "" { |
| 24 | return comspec |
| 25 | } |
| 26 | if systemRoot := os.Getenv("SystemRoot"); systemRoot != "" { |
| 27 | return filepath.Join(systemRoot, "System32", "cmd.exe") |
| 28 | } |
| 29 | return "cmd.exe" |
| 30 | } |
| 31 | |
| 32 | // DetectShell returns the appropriate shell binary and its argument prefix |
| 33 | // for the current platform. |
no outgoing calls