aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_linux_mipsx.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_linux_mipsx.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_linux_mipsx.go')
-rw-r--r--src/syscall/syscall_linux_mipsx.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/syscall/syscall_linux_mipsx.go b/src/syscall/syscall_linux_mipsx.go
index 377946fc92..99a3fad401 100644
--- a/src/syscall/syscall_linux_mipsx.go
+++ b/src/syscall/syscall_linux_mipsx.go
@@ -119,8 +119,10 @@ func Pipe2(p []int, flags int) (err error) {
}
var pp [2]_C_int
err = pipe2(&pp, flags)
- p[0] = int(pp[0])
- p[1] = int(pp[1])
+ if err == nil {
+ p[0] = int(pp[0])
+ p[1] = int(pp[1])
+ }
return
}
@@ -130,8 +132,11 @@ func Pipe(p []int) (err error) {
if len(p) != 2 {
return EINVAL
}
- p[0], p[1], err = pipe()
- return
+ r, w, err := pipe()
+ if err == nil {
+ p[0], p[1] = r, w
+ }
+ return err
}
//sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error)