From: Brad Fitzpatrick Date: Fri, 14 Sep 2012 20:40:22 +0000 (-0700) Subject: os/exec: don't crash when out of fds X-Git-Tag: go1.1rc2~2447 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c5c2c8112f774b118b9251eb15c2df529ad454c;p=gostls13.git os/exec: don't crash when out of fds Command.Start could crash before if no fds were available because a nil *os.File of /dev/null was added to the cleanup list, which crashed before returning the proper error. R=golang-dev, iant CC=golang-dev https://golang.org/cl/6514043 --- diff --git a/src/pkg/os/exec/exec.go b/src/pkg/os/exec/exec.go index 3db3ab095d..c4907cd7d7 100644 --- a/src/pkg/os/exec/exec.go +++ b/src/pkg/os/exec/exec.go @@ -143,6 +143,9 @@ func (c *Cmd) argv() []string { func (c *Cmd) stdin() (f *os.File, err error) { if c.Stdin == nil { f, err = os.Open(os.DevNull) + if err != nil { + return + } c.closeAfterStart = append(c.closeAfterStart, f) return } @@ -182,6 +185,9 @@ func (c *Cmd) stderr() (f *os.File, err error) { func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err error) { if w == nil { f, err = os.OpenFile(os.DevNull, os.O_WRONLY, 0) + if err != nil { + return + } c.closeAfterStart = append(c.closeAfterStart, f) return }