aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec_windows_test.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-09-16 16:11:19 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2021-09-17 00:31:49 +0000
commit14e812bfc575400a02e9e7536344a3f78a6cba08 (patch)
treeaab7c0edb1668eee3a4005075d1ca829660fe449 /src/os/exec/exec_windows_test.go
parent8d2a9c32a28838978f5d4e477bbd6db4144005d3 (diff)
downloadgo-14e812bfc575400a02e9e7536344a3f78a6cba08.tar.gz
go-14e812bfc575400a02e9e7536344a3f78a6cba08.zip
syscall: do not use handle lists on windows when NoInheritHandles is true
If NoInheritHandles is passed, then we shouldn't attempt to do anything with handle lists. Otherwise CreateProcess fails with invalid param, because it's being told both to not inherit handles and to inherit certain handles. This commit fixes that by using the same logic for handle lists as it does for enabling or disabling handle inheritance. It also adds a test to make sure this doesn't regress again. Fixes #48040 Change-Id: I507261baeec263091738ab90157a991d917dc92f Reviewed-on: https://go-review.googlesource.com/c/go/+/350411 Reviewed-by: Patrik Nyblom <pnyb@google.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/os/exec/exec_windows_test.go')
-rw-r--r--src/os/exec/exec_windows_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/os/exec/exec_windows_test.go b/src/os/exec/exec_windows_test.go
index fbccffec0e..bd4dfb31da 100644
--- a/src/os/exec/exec_windows_test.go
+++ b/src/os/exec/exec_windows_test.go
@@ -10,6 +10,7 @@ package exec_test
import (
"io"
"os"
+ "os/exec"
"strconv"
"syscall"
"testing"
@@ -41,3 +42,16 @@ func TestPipePassing(t *testing.T) {
t.Error(err)
}
}
+
+func TestNoInheritHandles(t *testing.T) {
+ cmd := exec.Command("cmd", "/c exit 88")
+ cmd.SysProcAttr = &syscall.SysProcAttr{NoInheritHandles: true}
+ err := cmd.Run()
+ exitError, ok := err.(*exec.ExitError)
+ if !ok {
+ t.Fatalf("got error %v; want ExitError", err)
+ }
+ if exitError.ExitCode() != 88 {
+ t.Fatalf("got exit code %d; want 88", exitError.ExitCode())
+ }
+}