From 0bafe0e5b284d41052be418052f61ab03504d7f7 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 29 Jun 2015 11:19:33 +1000 Subject: [PATCH] syscall: return error instead of panicking in windows StartProcess Fixes #11417 Change-Id: Iacea829a48b39df0a4f751b06b19e918fbb713d0 Reviewed-on: https://go-review.googlesource.com/11604 Reviewed-by: Rob Pike --- src/os/os_windows_test.go | 9 +++++++++ src/syscall/exec_windows.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index 3ea0fc7f4f..ee19b2b33a 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -117,3 +117,12 @@ func TestStatJunctionLink(t *testing.T) { t.Fatalf("link should point to %v but points to %v instead", expected, got) } } + +func TestStartProcessAttr(t *testing.T) { + p, err := os.StartProcess(os.Getenv("COMSPEC"), []string{"/c", "cd"}, new(os.ProcAttr)) + if err != nil { + return + } + defer p.Wait() + t.Fatalf("StartProcess expected to fail, but succeeded.") +} diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go index cc1abc4d03..5a01843d2b 100644 --- a/src/syscall/exec_windows.go +++ b/src/syscall/exec_windows.go @@ -244,6 +244,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle if len(attr.Files) > 3 { return 0, 0, EWINDOWS } + if len(attr.Files) < 3 { + return 0, 0, EINVAL + } if len(attr.Dir) != 0 { // StartProcess assumes that argv0 is relative to attr.Dir, -- 2.50.0