diff options
Diffstat (limited to 'src/os/exec/exec_windows_test.go')
-rw-r--r-- | src/os/exec/exec_windows_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/os/exec/exec_windows_test.go b/src/os/exec/exec_windows_test.go index 8e31e47190f..35ae0b0b8af 100644 --- a/src/os/exec/exec_windows_test.go +++ b/src/os/exec/exec_windows_test.go @@ -7,14 +7,31 @@ package exec_test import ( + "fmt" "io" "os" "os/exec" "strconv" + "strings" "syscall" "testing" ) +func init() { + registerHelperCommand("pipehandle", cmdPipeHandle) +} + +func cmdPipeHandle(args ...string) { + handle, _ := strconv.ParseUint(args[0], 16, 64) + pipe := os.NewFile(uintptr(handle), "") + _, err := fmt.Fprint(pipe, args[1]) + if err != nil { + fmt.Fprintf(os.Stderr, "writing to pipe failed: %v\n", err) + os.Exit(1) + } + pipe.Close() +} + func TestPipePassing(t *testing.T) { r, w, err := os.Pipe() if err != nil { @@ -54,3 +71,28 @@ func TestNoInheritHandles(t *testing.T) { t.Fatalf("got exit code %d; want 88", exitError.ExitCode()) } } + +// start a child process without the user code explicitly starting +// with a copy of the parent's SYSTEMROOT. +// (See issue 25210.) +func TestChildCriticalEnv(t *testing.T) { + cmd := helperCommand(t, "echoenv", "SYSTEMROOT") + + // Explicitly remove SYSTEMROOT from the command's environment. + var env []string + for _, kv := range cmd.Environ() { + k, _, ok := strings.Cut(kv, "=") + if !ok || !strings.EqualFold(k, "SYSTEMROOT") { + env = append(env, kv) + } + } + cmd.Env = env + + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatal(err) + } + if strings.TrimSpace(string(out)) == "" { + t.Error("no SYSTEMROOT found") + } +} |