Opened 2 months ago

Last modified 2 months ago

#19048 new bug

*at() methods accept -1 for AT_FDCWD

Reported by: bhaible Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: System/POSIX Version: R1/beta5
Keywords: Cc:
Blocked By: Blocking: #19049, #19050, #19051, #19052, #19053, #19054, #19055, #19056, #19057, #19058, #19059, #19061
Platform: All

Description

POSIX https://pubs.opengroup.org/onlinepubs/9799919799/functions/readlink.html specifies that the readlinkat() function "shall fail" with error code EBADF if "The path argument does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor open for reading or searching."

This does not work in Haiku hrev57823 (from 2024-07-15): it fails with error code ENOENT instead.

How to reproduce: Compile and run the attached test program.

gcc -Wall foo.c
./a.out

Expected output:

ret = -1, errno == EBADF
OK

Actual output:

ret = -1, errno == No such file or directory
a.out: foo.c:20:main: ret < 0 && errno == EBADF
Kill Thread

Attachments (1)

foo.c (440 bytes ) - added by bhaible 2 months ago.
test case foo.c

Download all attachments as: .zip

Change History (16)

by bhaible, 2 months ago

Attachment: foo.c added

test case foo.c

comment:1 by waddlesplash, 2 months ago

This, and all the other *at() tickets you have opened today, all have one and the same cause: -1 used to be the value for AT_FDCWD on Haiku. This was changed to -100 so things are clearer, but the kernel still accepts -1 so we don't break ABI too soon. (BeOS did not have AT_FDCWD, so we can change this without breaking ABI with BeOS.)

If one uses a large positive but nonexistent FD, then the tests all work as expected.

comment:2 by bhaible, 2 months ago

If one uses a large positive but nonexistent FD, then the tests all work as expected.

I confirm this part: I tried fd = 99, and got EBADF in this case.

comment:3 by waddlesplash, 2 months ago

Summary: readlinkat() does not fail with EBADF when it should*at() methods accept -1 for AT_FDCWD

I've adjusted things in hrev58059 so that the kernel at least rejects anything which isn't -1 or AT_FDCWD, so -2 and other such values should now trigger the error.

Changing this ticket's title and will consolidate the other tickets into it.

comment:4 by waddlesplash, 2 months ago

Blocking: 19049 added

comment:5 by waddlesplash, 2 months ago

Blocking: 19050 added

comment:6 by waddlesplash, 2 months ago

Blocking: 19051 added

comment:7 by waddlesplash, 2 months ago

Blocking: 19052 added

comment:8 by waddlesplash, 2 months ago

Blocking: 19053 added

comment:9 by waddlesplash, 2 months ago

Blocking: 19054 added

comment:10 by waddlesplash, 2 months ago

Blocking: 19055 added

comment:11 by waddlesplash, 2 months ago

Blocking: 19056 added

comment:12 by waddlesplash, 2 months ago

Blocking: 19057 added

comment:13 by waddlesplash, 2 months ago

Blocking: 19058 added

comment:14 by waddlesplash, 2 months ago

Blocking: 19059 added

comment:15 by waddlesplash, 2 months ago

Blocking: 19061 added
Note: See TracTickets for help on using tickets.