-
- Downloads
os/exec: avoid NewFile on unknown FDs
exec_test.go's init function uses os.NewFile(fd) + f.Stat as a portable mechanism to determine if an FD is in use. Unfortunately, the current use is racy: if an unused FD becomes used between NewFile and f.Close, then we will unintentionally close an FD we do not use. We cannot simply drop Close, as the finalizer will close the FD. We could hold all of the os.Files in a global for the lifetime of the process, but the need for such a hack is indicative of the larger problem: we should not create an os.File for an FD that we do not own. Instead, the new fdtest.Exists provides a helper that performs the equivalent of fstat(2) on each OS to determine if the FD is valid, without using os.File. We also reuse this helper on a variety of other tests that look at open FDs. Fixes #49533 Change-Id: I36e2bdb15f271ab01e55c18db6564271995a15af Reviewed-on: https://go-review.googlesource.com/c/go/+/364035 Trust: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by:Bryan C. Mills <bcmills@google.com>
Showing
- src/go/build/deps_test.go 3 additions, 0 deletionssrc/go/build/deps_test.go
- src/os/exec/exec_test.go 20 additions, 112 deletionssrc/os/exec/exec_test.go
- src/os/exec/internal/fdtest/exists_js.go 18 additions, 0 deletionssrc/os/exec/internal/fdtest/exists_js.go
- src/os/exec/internal/fdtest/exists_plan9.go 20 additions, 0 deletionssrc/os/exec/internal/fdtest/exists_plan9.go
- src/os/exec/internal/fdtest/exists_test.go 21 additions, 0 deletionssrc/os/exec/internal/fdtest/exists_test.go
- src/os/exec/internal/fdtest/exists_unix.go 19 additions, 0 deletionssrc/os/exec/internal/fdtest/exists_unix.go
- src/os/exec/internal/fdtest/exists_windows.go 12 additions, 0 deletionssrc/os/exec/internal/fdtest/exists_windows.go
- src/os/exec/read3.go 41 additions, 51 deletionssrc/os/exec/read3.go
Loading
Please register or sign in to comment