]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.17] os/exec: return clear error for missing cmd.Path
authorRuss Cox <rsc@golang.org>
Tue, 3 May 2022 19:14:56 +0000 (15:14 -0400)
committerAlex Rakoczy <alex@golang.org>
Fri, 27 May 2022 14:57:14 +0000 (14:57 +0000)
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 960ffa98ce73ef2c2060c84c7ac28d37a83f345e)
Reviewed-on: https://go-review.googlesource.com/c/go/+/408578
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/os/exec/exec.go
src/os/exec/exec_test.go

index 0c495755116f5254030d45284ea31515cadb8487..505de58e84dad724775a9c3042239afeeaea55ff 100644 (file)
@@ -374,6 +374,9 @@ func lookExtensions(path, dir string) (string, error) {
 // The Wait method will return the exit code and release associated resources
 // once the command exits.
 func (c *Cmd) Start() error {
+       if c.Path == "" && c.lookPathErr == nil {
+               c.lookPathErr = errors.New("exec: no command")
+       }
        if c.lookPathErr != nil {
                c.closeDescriptors(c.closeAfterStart)
                c.closeDescriptors(c.closeAfterWait)
index d854e0de843d69eff3da155b0710812c412d068b..a951be718d37f5fbb64bf610ab7c86f18451de9f 100644 (file)
@@ -1156,3 +1156,11 @@ func TestChildCriticalEnv(t *testing.T) {
                t.Error("no SYSTEMROOT found")
        }
 }
+
+func TestNoPath(t *testing.T) {
+       err := new(exec.Cmd).Start()
+       want := "exec: no command"
+       if err == nil || err.Error() != want {
+               t.Errorf("new(Cmd).Start() = %v, want %q", err, want)
+       }
+}