diff options
author | Russ Cox <rsc@golang.org> | 2021-12-08 18:06:41 -0500 |
---|---|---|
committer | Filippo Valsorda <filippo@golang.org> | 2021-12-09 12:28:59 +0000 |
commit | 99950270f3cf52cccc6966d8668ff21b573bb6f5 (patch) | |
tree | e5892ff3760a98811d3eb69665c56e19d1a3bbd9 /src/syscall/syscall_openbsd.go | |
parent | 44a3fb49d99cc8a4de4925b69650f97bb07faf1d (diff) | |
download | go-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_openbsd.go')
-rw-r--r-- | src/syscall/syscall_openbsd.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/syscall/syscall_openbsd.go b/src/syscall/syscall_openbsd.go index 5a5ba5a51b..18eafe3521 100644 --- a/src/syscall/syscall_openbsd.go +++ b/src/syscall/syscall_openbsd.go @@ -72,8 +72,10 @@ func Pipe2(p []int, flags int) 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 err } |