syscall: don't call Setgroups if Credential.Groups is empty
Setgroups with zero-length groups is no-op for changing groups and
supposed to be used only for determining curent groups length. Also
because we deny setgroups by default if use GidMappings we have
unnecessary error from that no-op syscall.
Change-Id: I8f74fbca9190a3dcbbef1d886c518e01fa05eb62
Reviewed-on: https://go-review.googlesource.com/13938
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go
index 60d2734..8c87736 100644
--- a/src/syscall/exec_linux_test.go
+++ b/src/syscall/exec_linux_test.go
@@ -109,3 +109,11 @@
t.Fatalf("Unprivileged gid_map rewriting with GidMappingsEnableSetgroups must fail")
}
}
+
+func TestEmptyCredGroupsDisableSetgroups(t *testing.T) {
+ cmd := whoamiCmd(t, os.Getuid(), os.Getgid(), false)
+ cmd.SysProcAttr.Credential = &syscall.Credential{}
+ if err := cmd.Run(); err != nil {
+ t.Fatal(err)
+ }
+}