casaroli opened a new pull request, #20752:
URL: https://github.com/apache/nuttx/pull/20752

   ## Summary
   
   POSIX says that an empty path names no file, so the call fails with 
`ENOENT`. `access("")`, `stat("")`, `lstat("")` and `open("")` already do this. 
The `*at()` functions did not: `lib_getfullpath()` turned `""` into the 
directory itself (`$PWD/` or the path of `dirfd`). So `faccessat(AT_FDCWD, "", 
X_OK)` returned 0, `fstatat(AT_FDCWD, "", 0)` returned the current directory, 
and `openat(AT_FDCWD, "")` failed with `ENXIO`.
   
   - The second commit makes `lib_getfullpath()` return `-ENOENT` for `""`. 
This fixes all `*at()` functions at once: `faccessat`, `fstatat`, `openat`, 
`mkdirat`, `unlinkat`, `fchownat`, `linkat`, `symlinkat`, `readlinkat`, 
`utimensat`, `renameat`, `mkfifoat` and `mknodat`.
   - `fstatat(fd, "", AT_EMPTY_PATH)` worked only because of that bug. The 
first commit makes `fstatat()` handle `AT_EMPTY_PATH` itself (`fstat(dirfd)`, 
or `"."` for `AT_FDCWD`), so it keeps working.
   
   ## Impact
   
   The `*at()` functions now fail with `ENOENT` for an empty path, as POSIX 
requires. `fstatat()` with `AT_EMPTY_PATH` does not change.
   
   ## Testing
   
   A test program on `qemu-armv8a:knsh` (QEMU 11 with HVF on an Apple M4):
   
   | Check | master | this PR |
   |---|---|---|
   | `access("")`, `stat("")`, `lstat("")`, `open("")` | `ENOENT` | `ENOENT` |
   | `faccessat(AT_FDCWD, "")` | 0 | `ENOENT` |
   | `fstatat(AT_FDCWD, "", 0)` | 0 | `ENOENT` |
   | `fstatat(dirfd, "", 0)` | 0 | `ENOENT` |
   | `openat(AT_FDCWD, "")` | `ENXIO` | `ENOENT` |
   | `fstatat()` with `AT_EMPTY_PATH` (`AT_FDCWD`, a directory fd, a file fd) | 
ok | ok |
   
   `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` ends with `ostest_main: 
Exiting with status 0`. `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to