aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2023-07-12 14:01:26 -0700
committerGopher Robot <gobot@golang.org>2023-07-25 16:33:33 +0000
commitd4dd1de19fcef835fca14ad8cb590dbfcf8e9859 (patch)
treea5e12f9f95cbd8ccdbe07c8f653d373563c840f2 /src/runtime/testdata
parent862fa6d099fb046e90efd537b2c0ac2667c23d90 (diff)
downloadgo-d4dd1de19fcef835fca14ad8cb590dbfcf8e9859.tar.xz
runtime: enforce standard file descriptors open on init on unix
On Unix-like platforms, enforce that the standard file descriptions (0, 1, 2) are always open during initialization. If any of the FDs are closed, we open them pointing at /dev/null, or fail. Fixes #60641 Change-Id: Iaab6b3f3e5ca44006ae3ba3544d47da9a613f58f Reviewed-on: https://go-review.googlesource.com/c/go/+/509020 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/testdata')
-rw-r--r--src/runtime/testdata/testfds/main.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/runtime/testdata/testfds/main.go b/src/runtime/testdata/testfds/main.go
new file mode 100644
index 0000000000..238ba469a3
--- /dev/null
+++ b/src/runtime/testdata/testfds/main.go
@@ -0,0 +1,29 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "fmt"
+ "io"
+ "log"
+ "os"
+)
+
+func main() {
+ f, err := os.OpenFile(os.Getenv("TEST_OUTPUT"), os.O_CREATE|os.O_RDWR, 0600)
+ if err != nil {
+ log.Fatalf("os.Open failed: %s", err)
+ }
+ defer f.Close()
+ b, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ log.Fatalf("io.ReadAll(os.Stdin) failed: %s", err)
+ }
+ if len(b) != 0 {
+ log.Fatalf("io.ReadAll(os.Stdin) returned non-nil: %x", b)
+ }
+ fmt.Fprintf(os.Stdout, "stdout\n")
+ fmt.Fprintf(os.Stderr, "stderr\n")
+}