diff options
Diffstat (limited to 'libgo/go/syscall/exec_bsd.go')
-rw-r--r-- | libgo/go/syscall/exec_bsd.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libgo/go/syscall/exec_bsd.go b/libgo/go/syscall/exec_bsd.go index c8eed532db7..a07129c8253 100644 --- a/libgo/go/syscall/exec_bsd.go +++ b/libgo/go/syscall/exec_bsd.go @@ -38,10 +38,18 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr i int ) + // 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. @@ -136,7 +144,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 = raw_dup2(pipe, nextfd) if err1 != 0 { @@ -217,11 +224,6 @@ childerror: for { raw_exit(253) } - - // Calling panic is not actually safe, - // but the for loop above won't break - // and this shuts up the compiler. - panic("unreached") } // Try to open a pipe with O_CLOEXEC set on both file descriptors. |