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

FD 0 is a valid file descriptor #199

Closed
mzyngier opened this issue Oct 15, 2020 · 2 comments · Fixed by #200
Closed

FD 0 is a valid file descriptor #199

mzyngier opened this issue Oct 15, 2020 · 2 comments · Fixed by #200
Labels
hidraw Related to Linux/hidraw backend

Comments

@mzyngier
Copy link

I may have reported this issue against a stale repository, so here it is again:

signal11/hidapi#462

Short story: File descriptor 0 is perfectly valid, and shouldn't be considered as an error.

hidapi/linux/hid.c

Lines 668 to 671 in d2c3a98

dev->device_handle = open(path, O_RDWR);
/* If we have a good handle, return it. */
if (dev->device_handle > 0) {

@z3ntu
Copy link
Collaborator

z3ntu commented Oct 15, 2020

Relevant part from open(2):

RETURN VALUE
open(), openat(), and creat() return the new file descriptor (a nonnegative integer), or -1 if an error occurred (in which case, errno is set appropriately).

@Youw
Copy link
Member

Youw commented Oct 15, 2020

(a nonnegative integer)

so I guess 0 is a nonnegative integer, looks valid

@mzyngier would you care to submit a PR?

mzyngier pushed a commit to mzyngier/hidapi that referenced this issue Oct 16, 2020
The open systcall is allowed to return 0 as a valid file descriptor,
and considering it an error breaks environments where unnecessary
fds are closed before executing untrusted processes.

Fixes: libusb#199

Signed-off-by: Marc Zyngier <maz@kernel.org>
@Youw Youw closed this as completed in #200 Oct 20, 2020
Youw pushed a commit that referenced this issue Oct 20, 2020
The open systcall is allowed to return 0 as a valid file descriptor,
and considering it an error breaks environments where unnecessary
fds are closed before executing untrusted processes.

Fixes: #199

Signed-off-by: Marc Zyngier <maz@kernel.org>
Dids pushed a commit to Didstopia/SDL that referenced this issue Nov 21, 2020
spurious pushed a commit to spurious/SDL-mirror that referenced this issue Nov 21, 2020
berenm pushed a commit to bminor/SDL that referenced this issue Nov 22, 2020
Youw pushed a commit that referenced this issue Nov 23, 2020
The open systcall is allowed to return 0 as a valid file descriptor,
and considering it an error breaks environments where unnecessary
fds are closed before executing untrusted processes.

Fixes: #199

Signed-off-by: Marc Zyngier <maz@kernel.org>
@mcuee mcuee added the hidraw Related to Linux/hidraw backend label Dec 11, 2020
Sibras pushed a commit to ShiftMediaProject/SDL that referenced this issue Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hidraw Related to Linux/hidraw backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants