Skip to content

stdio: implement tmpnam() and tempnam() functions#478

Merged
julianuziemblo merged 4 commits into
masterfrom
julianuziemblo/RTOS-1333
Jun 15, 2026
Merged

stdio: implement tmpnam() and tempnam() functions#478
julianuziemblo merged 4 commits into
masterfrom
julianuziemblo/RTOS-1333

Conversation

@julianuziemblo

@julianuziemblo julianuziemblo commented May 22, 2026

Copy link
Copy Markdown
Contributor

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo changed the title Julianuziemblo/rtos 1333 stdio: implement tmpnam() and tempnam() functions May 22, 2026
@github-actions

github-actions Bot commented May 22, 2026

Copy link
Copy Markdown

Unit Test Results

11 020 tests  +160   10 350 ✅ +160   52m 51s ⏱️ -7s
   680 suites + 10      670 💤 ±  0 
     1 files   ±  0        0 ❌ ±  0 

Results for commit c6a8782. ± Comparison against base commit d2db0c2.

♻️ This comment has been updated with latest results.

@julianuziemblo

Copy link
Copy Markdown
Contributor Author

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.

@julianuziemblo julianuziemblo marked this pull request as draft May 22, 2026 13:59
@nalajcie

Copy link
Copy Markdown
Member

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 Depends-On: in PR description (as described in https://youtrack.phoenix-rtos.com/articles/CI-A-23070284/Github)

@julianuziemblo

Copy link
Copy Markdown
Contributor Author

if you would use the same branch name for related changes across all submodules, these changes would compile and test succesfully.

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.

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 472358f to b3e65de Compare May 26, 2026 08:35
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from b3e65de to 8d98614 Compare June 12, 2026 10:45
@julianuziemblo julianuziemblo marked this pull request as ready for review June 12, 2026 10:45
@julianuziemblo julianuziemblo requested a review from a team June 12, 2026 11:15
@ziemleszcz

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 8d98614 to 7260def Compare June 12, 2026 12:05
@julianuziemblo

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread include/stdio.h Outdated
Comment thread include/stdio.h Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 7260def to 21f3e64 Compare June 12, 2026 14:27
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 21f3e64 to a399db6 Compare June 12, 2026 14:38
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from a399db6 to 97ebe07 Compare June 12, 2026 15:35
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 97ebe07 to 1ea3ca6 Compare June 15, 2026 12:25
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 1ea3ca6 to bd9287d Compare June 15, 2026 12:27
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch 2 times, most recently from 09f0a22 to ecf52ad Compare June 15, 2026 13:18
Comment thread stdlib/mktemp.c Outdated
Comment thread stdlib/mktemp.c
Comment thread stdlib/mktemp.c Outdated
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from ecf52ad to f6e8f8a Compare June 15, 2026 14:33
Comment thread stdlib/mktemp.c Outdated
YT: RTOS-1333
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch 2 times, most recently from 3aae880 to fd784ce Compare June 15, 2026 14:43
Comment thread stdlib/mktemp.c Outdated
Improve readability, define template strings, minor bug fixes

YT: RTOS-1333
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from fd784ce to 0fb2cc4 Compare June 15, 2026 15:14
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1333 branch from 0fb2cc4 to c6a8782 Compare June 15, 2026 15:33
@julianuziemblo julianuziemblo merged commit fb9670d into master Jun 15, 2026
47 checks passed
@julianuziemblo julianuziemblo deleted the julianuziemblo/RTOS-1333 branch June 15, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants