summaryrefslogtreecommitdiff
path: root/src/syscall/exec_unix.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-05-01 12:26:30 -0700
committerIan Lance Taylor <iant@golang.org>2020-05-01 21:57:29 +0000
commitbe08e10b3bc07f3a4e7b27f44d53d582e15fd6c7 (patch)
treeab435cf12ffcc4264f2e4f6064f1788ac473f9b8 /src/syscall/exec_unix.go
parent5c8715f70adf13411668b8de76e5fef78c8e3f32 (diff)
downloadgo-git-be08e10b3bc07f3a4e7b27f44d53d582e15fd6c7.tar.gz
syscall: if Setctty, require that Ctty be a child descriptor
Ctty was always handled as a child descriptor, but in some cases passing a parent descriptor would also work. This depended on unpredictable details of the implementation. Reject those cases to avoid confusion. Also reject setting both Setctty and Foreground, as they use Ctty in incompatible ways. It's unlikely that any programs set both fields, as they don't make sense together. Fixes #29458 Change-Id: Ieba2d625711fd4b82c8e65e1feed02fd1fb25e6d Reviewed-on: https://go-review.googlesource.com/c/go/+/231638 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/syscall/exec_unix.go')
-rw-r--r--src/syscall/exec_unix.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/syscall/exec_unix.go b/src/syscall/exec_unix.go
index b3798b6e04..0345af44f9 100644
--- a/src/syscall/exec_unix.go
+++ b/src/syscall/exec_unix.go
@@ -9,6 +9,7 @@
package syscall
import (
+ errorspkg "errors"
"internal/bytealg"
"runtime"
"sync"
@@ -187,6 +188,15 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
}
}
+ // Both Setctty and Foreground use the Ctty field,
+ // but they give it slightly different meanings.
+ if sys.Setctty && sys.Foreground {
+ return 0, errorspkg.New("both Setctty and Foreground set in SysProcAttr")
+ }
+ if sys.Setctty && sys.Ctty >= len(attr.Files) {
+ return 0, errorspkg.New("Setctty set but Ctty not valid in child")
+ }
+
// Acquire the fork lock so that no other threads
// create new fds that are not yet close-on-exec
// before we fork.