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: IsPermission returns false when reading a write-only file descriptor. #15629

Closed
Julio-Guerra opened this issue May 10, 2016 · 7 comments
Closed

Comments

@Julio-Guerra
Copy link

@Julio-Guerra Julio-Guerra commented May 10, 2016

  1. What version of Go are you using (go version)?

go version go1.6.1 linux/amd64

  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?

Given any file descriptor correctly opened with a write-only access level, reading from it correctly returns the errno EBADF as specified in read(2):

EBADF fd is not a valid file descriptor or is not open for reading.

But os.IsPermission() does not check this case and returns false instead of true.

https://play.golang.org/p/sPZWxH5JA7

The context provided by os.PathError should allow to return true correctly.

Regarding the case "fd is not a valid file descriptor", it could be excluded by also checking that the file descriptor is valid with something like fcntl(fd, F_GETFD) (but the fd is not in the error context).

@minux

This comment has been minimized.

Copy link
Member

@minux minux commented May 10, 2016

@Julio-Guerra

This comment has been minimized.

Copy link
Author

@Julio-Guerra Julio-Guerra commented May 10, 2016

@minux EBADF is used for this permission error as shown and explained (man 2 read) oO

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 10, 2016

Show us an example in which you do not construct the error value yourself.

@minux

This comment has been minimized.

Copy link
Member

@minux minux commented May 10, 2016

@Julio-Guerra

This comment has been minimized.

Copy link
Author

@Julio-Guerra Julio-Guerra commented May 10, 2016

You need a special device node to reproduce this. My exact case is a tty, but go playground's stdout is a pipe, so here is the exact same error I get with a correctly opened TTY device in write-only mode:
https://play.golang.org/p/Unzh0NGvaC
Note that EINVAL is returned with a regular file.

@minux the open flag plays a role twice: at open time and at read/write time.

@ianlancetaylor ianlancetaylor changed the title os: IsPermission() returns false when reading a write-only file descriptor. os: IsPermission returns false when reading a write-only file descriptor. May 10, 2016
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 10, 2016

Thanks for the example. I guess this hinges on what we want "permission error" to mean.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Oct 19, 2016

"Bad use of file descriptor" is not a permission error, any more than closing an already-closed file descriptor is.

@rsc rsc closed this Oct 19, 2016
@golang golang locked and limited conversation to collaborators Oct 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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