aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/syscall/exec_linux.go
diff options
context:
space:
mode:
authorCosmos Nicolaou <cnicolaou@google.com>2013-04-30 11:52:23 -0700
committerRob Pike <r@golang.org>2013-04-30 11:52:23 -0700
commitb493f0a868982711903c01f759a56c448d908b12 (patch)
tree90d0f818c037929139a5ebcc55197ee76d62347f /src/pkg/syscall/exec_linux.go
parent479b1241b5c7451d367d55a4afa9f071f9beb4f6 (diff)
downloadgo-b493f0a868982711903c01f759a56c448d908b12.tar.xz
syscall: fix a bug in the shuffling of file descriptors in StartProcess on Linux.
R=iant, iant, r, bradfitz CC=golang-dev https://golang.org/cl/8334044
Diffstat (limited to 'src/pkg/syscall/exec_linux.go')
-rw-r--r--src/pkg/syscall/exec_linux.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/pkg/syscall/exec_linux.go b/src/pkg/syscall/exec_linux.go
index a8dc672b8c..ddd946ed20 100644
--- a/src/pkg/syscall/exec_linux.go
+++ b/src/pkg/syscall/exec_linux.go
@@ -40,11 +40,18 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
i int
)
- // guard against side effects of shuffling fds below.
+ // Guard against side effects of shuffling fds below.
+ // Make sure that nextfd is beyond any currently open files so
+ // that we can't run the risk of overwriting any of them.
fd := make([]int, len(attr.Files))
+ nextfd = len(attr.Files)
for i, ufd := range attr.Files {
+ if nextfd < int(ufd) {
+ nextfd = int(ufd)
+ }
fd[i] = int(ufd)
}
+ nextfd++
// About to call fork.
// No more allocation or calls of non-assembly functions.
@@ -143,7 +150,6 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
// Pass 1: look for fd[i] < i and move those up above len(fd)
// so that pass 2 won't stomp on an fd it needs later.
- nextfd = int(len(fd))
if pipe < nextfd {
_, _, err1 = RawSyscall(SYS_DUP2, uintptr(pipe), uintptr(nextfd), 0)
if err1 != 0 {