The workaround in CL
69970044 introduced a panic when StartProcess is
called with empty argv. Check the length before trying to access it.
Change-Id: Ic948d86c7067a21c484ba24e100d1f1f80179730
Reviewed-on: https://go-review.googlesource.com/c/go/+/500415
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
return 0, err
}
- if (runtime.GOOS == "freebsd" || runtime.GOOS == "dragonfly") && len(argv[0]) > len(argv0) {
+ if (runtime.GOOS == "freebsd" || runtime.GOOS == "dragonfly") && len(argv) > 0 && len(argv[0]) > len(argv0) {
argvp[0] = argv0p
}
t.Errorf("exec rlimit = %d, want %d", v, orig)
}
}
+
+func TestForkExecNilArgv(t *testing.T) {
+ defer func() {
+ if p := recover(); p != nil {
+ t.Fatal("forkExec panicked")
+ }
+ }()
+
+ // We don't really care what the result of forkExec is, just that it doesn't
+ // panic, so we choose something we know won't actually spawn a process (probably).
+ syscall.ForkExec("/dev/null", nil, nil)
+}