Skip to content

Commit 590b53f

Browse files
rsctoothrot
authored andcommitted
[release-branch.go1.17] os/exec: return clear error for missing cmd.Path
Following up on CL 403694, there is a bit of confusion about when Path is and isn't set, along with now the exported Err field. Catch the case where Path and Err (and lookPathErr) are all unset and give a helpful error. Updates #52574 Followup after #43724. Fixes #53056 Fixes CVE-2022-30580 Change-Id: I03205172aef3801c3194f5098bdb93290c02b1b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/403759 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> (cherry picked from commit 960ffa9) Reviewed-on: https://go-review.googlesource.com/c/go/+/408578 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 2be03d7 commit 590b53f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/os/exec/exec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ func lookExtensions(path, dir string) (string, error) {
374374
// The Wait method will return the exit code and release associated resources
375375
// once the command exits.
376376
func (c *Cmd) Start() error {
377+
if c.Path == "" && c.lookPathErr == nil {
378+
c.lookPathErr = errors.New("exec: no command")
379+
}
377380
if c.lookPathErr != nil {
378381
c.closeDescriptors(c.closeAfterStart)
379382
c.closeDescriptors(c.closeAfterWait)

src/os/exec/exec_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,3 +1156,11 @@ func TestChildCriticalEnv(t *testing.T) {
11561156
t.Error("no SYSTEMROOT found")
11571157
}
11581158
}
1159+
1160+
func TestNoPath(t *testing.T) {
1161+
err := new(exec.Cmd).Start()
1162+
want := "exec: no command"
1163+
if err == nil || err.Error() != want {
1164+
t.Errorf("new(Cmd).Start() = %v, want %q", err, want)
1165+
}
1166+
}

0 commit comments

Comments
 (0)