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
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@Julio-Guerra
Copy link

  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
Copy link
Member

minux commented May 10, 2016 via email

@Julio-Guerra
Copy link
Author

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

@ianlancetaylor
Copy link
Contributor

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

@minux
Copy link
Member

minux commented May 10, 2016 via email

@Julio-Guerra
Copy link
Author

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
Copy link
Contributor

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

@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Go1.8Maybe May 10, 2016
@quentinmit quentinmit added NeedsFix The path to resolution is known, but the work has not been done. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Oct 10, 2016
@rsc
Copy link
Contributor

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 as completed 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.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants