casaroli opened a new pull request, #21563:
URL: https://github.com/apache/nuttx/pull/21563
## Summary
mktemp() tries names until stat() fails with ENOENT. When stat() fails with
another error, such as ENAMETOOLONG, ENOTDIR or EACCES, every name gives the
same error. mktemp() then tried every name, up to `UINT32_MAX` of them, and did
not return. mkstemp(), mkostemps(), mkdtemp(), tempnam(), tmpnam() and
memfd_create() call mktemp(), so they did not return either. For example,
`mkstemp("/tmp/<a name longer than NAME_MAX>XXXXXX")` hangs.
This PR makes mktemp() return NULL at the first stat() error other than
ENOENT, with errno from stat(). mkstemp(), mkostemps(), mkdtemp(), tempnam()
and tmpnam() already return an error when mktemp() gives NULL. memfd_create()
does not check the result of mktemp(), but its open() of the same name then
fails with the same error.
## Impact
libc only. The same in flat, protected and kernel builds; no arch code.
These calls now fail with the error of stat() where they did not return.
Nothing changes when stat() gives ENOENT or success. No Documentation change.
A test follows in nuttx-apps (testing/libc/mktemp), with a depends-on line
for this PR.
## Testing
Test program `mktemplong.c`: mkstemp() in `/tmp` (no change), then mktemp(),
mkstemp() and mkdtemp() with a name component longer than `NAME_MAX` (expect
NULL or -1 and ENAMETOOLONG). The same program passes 4/4 with the macOS libc.
- qemu-armv8a:knsh (kernel build, arm64, QEMU) with `FS_TMPFS`: on master
the first long name case does not return; this PR 4/4 PASS (ENAMETOOLONG).
ostest exits 0.
- qemu-armv8a:nsh (flat build, arm64) and qemu-armv7a:nsh (flat build,
32-bit arm, arm-none-eabi-gcc 15.3), the test as a builtin (on a tree with this
PR and three unrelated small libc and header fixes): 4/4 PASS, ostest exits 0.
- mps2-an500:knsh (protected build, Cortex-M7, QEMU) with `FS_TMPFS`: 4/4
PASS.
- The new test of the nuttx-apps PR (`mktemp_test`), qemu-armv8a:nsh: it
passes with this PR and fails on master after its 10-second limit; ostest exits
0 after it in both runs.
- Build only, with `EXTRAFLAGS="-Wno-cpp -Werror"`: nucleo-f072rb:nsh
(Cortex-M0), mps2-an500:knsh (protected), rv-virt:pnsh64 (protected, RISC-V),
esp32s3-devkit:nsh (Xtensa): all build with no compiler warning.
`tools/checkpatch.sh -c -u -m -g origin/master..HEAD` 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]