Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os, x/build: only write permissions 0222 for file result in successful read for linux-amd64 #38608

Open
odeke-em opened this issue Apr 23, 2020 · 5 comments

Comments

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Apr 23, 2020

Coming here from https://go-review.googlesource.com/c/go/+/229357/3#message-c7922ea647b703faa8e858428f47221a6d921275 and https://storage.googleapis.com/go-build-log/b49db1e9/linux-amd64_454ff41f.log in which we have an odd test failure

# go run run.go -- fixedbugs/issue36437.go
incorrect output
Expected a non-nil error, but got:
	""
want
	"open /workdir/tmp/33921360662258/main.go: permission denied\n"
FAIL	fixedbugs/issue36437.go	0.291s
2020/04/22 23:32:59 Failed: exit status 1
go tool dist: FAILED

in which the relevant test is

package main

import (
        "fmt"
        "io/ioutil"
        "os"
        "os/exec"
        "path/filepath"
)

func main() {
        tmpDir, err := ioutil.TempDir("", "issue36437")
        if err != nil {
                panic(err)
        }
        defer os.RemoveAll(tmpDir)

        msgOrErr := func(bmsg []byte, err error) string {
                msg := string(bmsg)
                if msg == "" && err != nil {
                        msg = err.Error()
                }
                return msg
        }

        // 2. Invoke the compiler with a file that we don't have read permissions to.
        path := filepath.Join(tmpDir, "main.go")
        if err := ioutil.WriteFile(path, []byte("package p"), 0222); err != nil {
                panic(err)
        }
        output, err = exec.Command("go", "tool", "compile", path).CombinedOutput()
        want := fmt.Sprintf("open %s: permission denied\n", path)
        if g, w := msgOrErr(output, err), want; g != w {
                panic(fmt.Sprintf("Expected a non-nil error, but got:\n\t%q\nwant\n\t%q", g, w))
        }
}

Is this perhaps just a problem with the builder? I'd expect that 0222 would make a file writable but would error on reading; other GOOS-GOARCH combinations work properly but not this one.

@odeke-em
Copy link
Member Author

@odeke-em odeke-em commented Apr 23, 2020

I can't test it out unfortunately on my home machine at Linux as it malfunctioned.

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 23, 2020

I don't know why the other TryBots would have succeeded, but most of the linux builders run as root, so file permissions are often ignored. (See #10719.)

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 25, 2020

Change https://golang.org/cl/229357 mentions this issue: cmd/compile: omit file:pos for non-existent, permission errors

@odeke-em
Copy link
Member Author

@odeke-em odeke-em commented Apr 25, 2020

Thank you @bcmills! That explains it for me.

gopherbot pushed a commit that referenced this issue Apr 30, 2020
Omits printing the file:line:column when trying to open either
* non-existent files
* files without permission

Given:
    go tool compile x.go

For either of x.go not existing, or if no read permissions:

* Before:
    x.go:0: open x.go: no such file or directory
    x.go:0: open x.go: permission denied

* After:
    open x.go: no such file or directory
    open x.go: permission denied

While here, noticed an oddity with the Linux builders, that appear
to always be running under root, hence the test for permission errors
with 0222 -W-*-W-*-W- can't pass on linux-amd64 builders.
The filed bug is #38608.

Fixes #36437

Change-Id: I9645ef73177c286c99547e3a0f3719fa07b35cb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/229357
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 30, 2020

Change https://golang.org/cl/231044 mentions this issue: test/fixedbugs: skip issue36347 since builders seem to be running on root

xujianhai666 added a commit to xujianhai666/go-1 that referenced this issue May 21, 2020
Omits printing the file:line:column when trying to open either
* non-existent files
* files without permission

Given:
    go tool compile x.go

For either of x.go not existing, or if no read permissions:

* Before:
    x.go:0: open x.go: no such file or directory
    x.go:0: open x.go: permission denied

* After:
    open x.go: no such file or directory
    open x.go: permission denied

While here, noticed an oddity with the Linux builders, that appear
to always be running under root, hence the test for permission errors
with 0222 -W-*-W-*-W- can't pass on linux-amd64 builders.
The filed bug is golang#38608.

Fixes golang#36437

Change-Id: I9645ef73177c286c99547e3a0f3719fa07b35cb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/229357
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.