stdio: implement tmpnam() and tempnam() functions#478
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the tmpnam and tempnam functions, moving the implementation to stdlib/mktemp.c and updating include/stdio.h with the required macro and prototype. The review identified several critical issues: a buffer overflow in tempnam when the prefix is null, broken retry logic in both functions because the template string is modified in place, a memory leak in tempnam when it fails to generate a name, and a lack of POSIX-compliant checks for the TMPDIR environment variable.
|
Drafting for now as added tests depend on tmpfile() tests, which depend on tmpfile() fixes. Will undraft after phoenix-rtos/phoenix-rtos-posixsrv#32 is merged. |
|
if you would use the same branch name for related changes across all submodules, these changes would compile and test succesfully. PLEASE always use the same branch name on related changes OR use |
it's not this here: as I wrote, I'm fixing tmpfile() in another branch and wanted to base tests for this PR on that branch for now as it adds "posixsrv" directory to tests, which I didn't want to duplicate across PRs. I'll undraft, rerun tests and add reviewers once that PR is merged. |
472358f to
b3e65de
Compare
b3e65de to
8d98614
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements the tmpnam and tempnam functions in stdlib/mktemp.c, removes the stub for tmpnam in posix/stubs.c, and updates include/stdio.h with the necessary declarations and the P_tmpdir macro. The review feedback highlights several POSIX compliance issues in the tempnam implementation: it needs to check the TMPDIR environment variable first, verify directory write permissions using access(), and limit the prefix pfx to a maximum of 5 characters during length calculation and string formatting.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
8d98614 to
7260def
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements the tmpnam and tempnam functions in stdlib/mktemp.c, removes the tmpnam stub from posix/stubs.c, and updates include/stdio.h with the corresponding declarations and the P_tmpdir macro. The review feedback highlights several critical issues: both functions risk infinite loops during persistent filename collisions and should limit retries to TMP_MAX; tempnam lacks POSIX compliance by omitting TMPDIR environment variable and writability checks; and tempnam is vulnerable to an out-of-bounds read if the directory path is empty.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
7260def to
21f3e64
Compare
21f3e64 to
a399db6
Compare
a399db6 to
97ebe07
Compare
YT: RTOS-1333
97ebe07 to
1ea3ca6
Compare
1ea3ca6 to
bd9287d
Compare
09f0a22 to
ecf52ad
Compare
ecf52ad to
f6e8f8a
Compare
YT: RTOS-1333
3aae880 to
fd784ce
Compare
Improve readability, define template strings, minor bug fixes YT: RTOS-1333
fd784ce to
0fb2cc4
Compare
0fb2cc4 to
c6a8782
Compare
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment