aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_solaris.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-08 18:06:41 -0500
committerFilippo Valsorda <filippo@golang.org>2021-12-09 12:28:59 +0000
commit99950270f3cf52cccc6966d8668ff21b573bb6f5 (patch)
treee5892ff3760a98811d3eb69665c56e19d1a3bbd9 /src/syscall/syscall_solaris.go
parent44a3fb49d99cc8a4de4925b69650f97bb07faf1d (diff)
downloadgo-99950270f3cf52cccc6966d8668ff21b573bb6f5.tar.gz
go-99950270f3cf52cccc6966d8668ff21b573bb6f5.zip
[release-branch.go1.16] syscall: avoid writing to p when Pipe(p) fails
Generally speaking Go functions make no guarantees about what has happened to result parameters on error, and Pipe is no exception: callers should avoid looking at p if Pipe returns an error. However, we had a bug in which ForkExec was using the content of p after a failed Pipe, and others may too. As a robustness fix, make Pipe avoid writing to p on failure. Updates #50057 Change-Id: Ie8955025dbd20702fabadc9bbe1d1a5ac0f36305 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1291271 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/370515 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alex Rakoczy <alex@golang.org>
Diffstat (limited to 'src/syscall/syscall_solaris.go')
-rw-r--r--src/syscall/syscall_solaris.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go
index daa4b88a71..7640aac25b 100644
--- a/src/syscall/syscall_solaris.go
+++ b/src/syscall/syscall_solaris.go
@@ -55,7 +55,9 @@ func Pipe(p []int) (err error) {
if e1 != 0 {
err = Errno(e1)
}
- p[0], p[1] = int(r0), int(w0)
+ if err == nil {
+ p[0], p[1] = int(r0), int(w0)
+ }
return
}