]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/work: ensure correct group for TestRespectSetgidDir
authorMark Pulford <mark@kyne.com.au>
Sat, 8 Dec 2018 16:30:08 +0000 (03:30 +1100)
committerBryan C. Mills <bcmills@google.com>
Thu, 13 Dec 2018 15:08:48 +0000 (15:08 +0000)
mkdir(2) inherits the parent directory group on *BSD (including Darwin),
and it may inherit on other platforms if the parent directory is SetGID.

This can cause TestRespectSetgidDir SetGID to fail when the process does
not have have permission for the inherited group on the new temporary
directory.

Fixes #29160

Change-Id: Iac05511e501dfe307a753f801223b1049cc0947d
Reviewed-on: https://go-review.googlesource.com/c/153357
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/work/build_test.go

index 010e17ee480578be4f6be3371fa9042ad5ee355e..a875ec1aa62fd746f28b8e82401d07222439ffa3 100644 (file)
@@ -227,6 +227,8 @@ func TestRespectSetgidDir(t *testing.T) {
                if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
                        t.Skip("can't set SetGID bit with chmod on iOS")
                }
+       case "windows", "plan9":
+               t.Skip("chown/chmod setgid are not supported on Windows and Plan 9")
        }
 
        var b Builder
@@ -245,11 +247,13 @@ func TestRespectSetgidDir(t *testing.T) {
        }
        defer os.RemoveAll(setgiddir)
 
-       if runtime.GOOS == "freebsd" {
-               err = os.Chown(setgiddir, os.Getuid(), os.Getgid())
-               if err != nil {
-                       t.Fatal(err)
-               }
+       // BSD mkdir(2) inherits the parent directory group, and other platforms
+       // can inherit the parent directory group via setgid. The test setup (chmod
+       // setgid) will fail if the process does not have the group permission to
+       // the new temporary directory.
+       err = os.Chown(setgiddir, os.Getuid(), os.Getgid())
+       if err != nil {
+               t.Fatal(err)
        }
 
        // Change setgiddir's permissions to include the SetGID bit.