Skip to content

fs: fix out-of-bounds write in mkdtemp for long prefixes#64770

Open
frandle331-yh wants to merge 1 commit into
nodejs:mainfrom
frandle331-yh:fix-mkdtemp-oob-write
Open

fs: fix out-of-bounds write in mkdtemp for long prefixes#64770
frandle331-yh wants to merge 1 commit into
nodejs:mainfrom
frandle331-yh:fix-mkdtemp-oob-write

Conversation

@frandle331-yh

Copy link
Copy Markdown

Mkdtemp() allocated the template buffer as length + strlen("XXXXXX"),
leaving no room for the terminating NUL byte that snprintf() writes. For
a single-byte prefix long enough to force the heap allocation path
(length + 6 > the stack-buffer threshold), snprintf() wrote the six 'X'
characters plus its NUL one byte past the end of the buffer -- a 1-byte
heap-buffer-overflow flagged by AddressSanitizer.

Allocate one extra byte for the NUL terminator, matching the + 1
already used by the sibling allocations in the same file.

Signed-off-by: frandle331-yh s1240100@gmail.com

Mkdtemp() allocated the template buffer as `length + strlen("XXXXXX")`,
leaving no room for the terminating NUL byte that snprintf() writes. For
a single-byte prefix long enough to force the heap allocation path
(length + 6 > the stack-buffer threshold), snprintf() wrote the six 'X'
characters plus its NUL one byte past the end of the buffer -- a 1-byte
heap-buffer-overflow flagged by AddressSanitizer.

Allocate one extra byte for the NUL terminator, matching the `+ 1`
already used by the sibling allocations in the same file.

Signed-off-by: frandle331-yh <s1240100@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants