ucrt: malloc the result of _getcwd and _fullpath given no buffer #74
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!74
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-74"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Olima34 on GitHub · 2026-11-26 13:41 UTC · original
Olima34:fix/ucrt-getcwd-fullpath-allocate→main· +54 −13 · 1 files · 5 commits · merged 2026-11-26 17:05 UTCWhat this changes
Given a null buffer,
_getcwdand_fullpathmade a leaked host string, then checked it againstmax, so_getcwd(NULL, 0)(Microsoft's own example, followed byfree) failed withERANGE. Had it succeeded, the title'sfree()would have been handed a blockmallocnever made. Both now return amallocblock, at leastmaxbytes for_getcwd, ignoringmaxfor_fullpath(reference), as_wgetcwdalready did._getcwdwith a buffer andmax <= 0is nowEINVAL, as for_wgetcwd, instead of writing a NUL into an empty buffer.New test
getcwd_and_fullpath_malloc_when_given_no_buffer.How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory(all pass, native probe tests included)cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with--all-features; clippy forx86_64-apple-darwinreports nothing in the files touched (host_posixis not built for Windows)cargo test --workspaceandcargo xtask policymainand passes with the changeChecklist
VICTORY_*variable and documented (none added)@LakshanSivakumar on GitHub · 2026-11-26 14:55 UTC · original · review (dismissed)
_getcwd and _fullpath with a NULL buffer now return a block the title can free. Thanks. (Minor follow-up: set errno when malloc fails.)
@Olima34 on GitHub · 2026-11-26 15:13 UTC · original
On the malloc path errno was already set:
heap::mallocgoes throughchecked, which setsENOMEMon a null result, and a comment at the call now says so. While checking, I found that_getcwd's other failure (the host'scurrent_dir) returned null without errno. It now sets it as_wgetcwddoes.@LakshanSivakumar on GitHub · 2026-11-26 15:55 UTC · original · approved these changes
Both follow-ups are in (errno on the malloc path is covered by checked, and _getcwd sets errno on a current_dir failure). CI is green. Approving.