From: miller Date: Tue, 13 Dec 2022 10:43:23 +0000 (+0000) Subject: syscall: fix closing of reordered FDs in plan9 ForkExec X-Git-Tag: go1.20rc2~1^2~32 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cb07765045aed5104a3df31507564ac99e6ddce8;p=gostls13.git syscall: fix closing of reordered FDs in plan9 ForkExec After dup'ing file descriptors in syscall.ProcAttr.Files to pass to the exec'ed process, the logic for closing the old descriptors was incorrect and could close the new descriptor instead. Fixes #57180 Change-Id: I7725f21a465ffba57050fe4e36f3d36ba181cfb2 Reviewed-on: https://go-review.googlesource.com/c/go/+/457115 Run-TryBot: David du Colombier <0intro@gmail.com> TryBot-Result: Gopher Robot Auto-Submit: Bryan Mills Reviewed-by: Ian Lance Taylor Reviewed-by: David du Colombier <0intro@gmail.com> Reviewed-by: Bryan Mills --- diff --git a/src/syscall/exec_plan9.go b/src/syscall/exec_plan9.go index d6b7890f55..8f28b5aa22 100644 --- a/src/syscall/exec_plan9.go +++ b/src/syscall/exec_plan9.go @@ -276,7 +276,7 @@ dirloop: // Pass 3: close fd[i] if it was moved in the previous pass. for i = 0; i < len(fd); i++ { - if fd[i] >= 0 && fd[i] != int(i) { + if fd[i] >= len(fd) { RawSyscall(SYS_CLOSE, uintptr(fd[i]), 0, 0) } }