Open CPestka opened 2 weeks ago
Think I found the issue.
From the kernel, in open.c line 1255:
/* Now handle the creative implementation of O_TMPFILE. */
if (flags & __O_TMPFILE) {
/*
* In order to ensure programs get explicit errors when trying
* to use O_TMPFILE on old kernels we enforce that O_DIRECTORY
* is raised alongside __O_TMPFILE.
*/
if (!(flags & O_DIRECTORY))
return -EINVAL;
if (!(acc_mode & MAY_WRITE))
return -EINVAL;
}
Adding .DIRECTORY = true to the flags indeed "solves" the problem, as that makes the call succeed.
I'm not sure what the "correct" behavior of zig should be in this case. The documentation of open(3) does not say that O_DIRECTORY should be supplied when O_TMPFILE is supplied and the c++ version apparently silently adds the flag, as it works without it. The options I guess would be to either also silently add that flag if the TMPFILE flag is set or to return an error if it is set, but missing the DIRECTORY flag.
Btw. I think that there might be two more cases that also would result in .INVAL being returned and thus crash.
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Passing .TMPFILE = true in the flags for posix.open() causes an unreachable to be tripped.
Code Snippet to reproduce:
Results in the output
Expected Behavior
I would expect, that in case there is actually incorrect usage of the open call, an error to be returned rather than a crash to occur. However I do not think this is incorrect usage. O_TMPFILE only requires the path to be passed to be a directory and either RDWR or WRONLY to be passed. Additionally the equivalent c++ works, as i would have expected.
Used fs is ext4, kernel version is 6.5.0-41-generic.