Repository navigation
Conversation
…xceeds INT_MAX FreeBSD 11.4 vsnprintf checks the size minus the terminator against INT_MAX before formatting and, when it is larger, sets errno to EOVERFLOW, writes a terminator to the buffer and returns EOF (lib/libc/stdio/vsnprintf.c:61-67). The guest formatted into the buffer and returned the length. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
fogydes
left a comment
There was a problem hiding this comment.
Reviewed the diff, verified FreeBSD 11.4 behavior, and built/ran the test suite locally.
Implementation: The helper SizeOverflowsInt(char* buffer, size_t size) checks if (size == 0 || size - 1 <= static_cast<size_t>(INT_MAX)) return false;. For oversized buffers, it sets errno = 84 (EOVERFLOW), places a null terminator in *buffer if non-null, and returns true, triggering -1 in both snprintf_nid_postfix and vsnprintf_nid_postfix.
- Size 0 correctly returns
false(allowing format query calls likesnprintf(nullptr, 0, ...)to succeed and calculate length without error). - Exact boundary
INT_MAX + 1is preserved (size - 1 <= INT_MAXremains true). - This matches FreeBSD 11.4
lib/libc/stdio/vsnprintf.c:61-67behavior.
Tests: Adds assertions covering INT_MAX + 2 and SIZE_MAX verifying both return -1, set errno = 84, and terminate output[0] == 0. Also asserts INT_MAX + 1 succeeds and formats correctly.
Local verification:
- Built
guest_formatting_testson Windows 11 with MinGW-w64 GCC 15.2.0 Release. - Ran
ctest --test-dir build-libs -R "^guest_formatting$" -V: Passed (0.19s, 10000 iterations). - CI is all green across Linux, Windows, macOS, and relinker matrix.
No issues found. Clean, standards-compliant fix with precise boundary checks.
|
Thanks for this. On the console, snprintf and vsnprintf don't check the size against INT_MAX: the size is passed straight through to the formatter, so a size above INT_MAX doesn't produce EOVERFLOW there (the same behaviour came up on #3982). Since we aim to match the console, this change would introduce a difference rather than fix one, so I'm closing it. Thank you for looking into it. |
What
snprintfandvsnprintfformatted into the buffer for any size and returned the length. FreeBSD 11.4vsnprintfrejects a size whose value minus one exceedsINT_MAX: it setserrnotoEOVERFLOW(84), stores a NUL in the buffer and returns -1 (lib/libc/stdio/vsnprintf.c:61-67). Both exports now do the same before formatting, on every host build; sizes up toINT_MAX + 1and size 0 are unchanged.Fixes #8510
git merge-treeagainstupstream/mainis clean.pr_overlapwas not run. No title is known to reach this; the change rests on the FreeBSD source line and a failing test.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main 5f7aa55 + this commit:
guest_formatting: fails (Formatting check failed) withFormatting.cpptaken back to main, passes with the change (3 of 3 runs). New cases:snprintfandvsnprintfwithINT_MAX + 2andSIZE_MAXreturn -1 withEOVERFLOWand an empty buffer;INT_MAX + 1still formats.guest_syslog(the only other caller ofvsnprintf, with small sizes) passes.python tools/check_conventions.py --base upstream/main: passes.Depends on: none. Unblocks: none. AI-assisted: yes.
AI-assisted (Claude Code).
Hinweis: Vorarbeit in fix(libc): reject oversized snprintf buffers on Windows #5070 (MarcZX10, geschlossen; xXPBSXx hatte dort bereits die Quellzeile bestaetigt). Dieser Branch ist ein eigener Neuaufbau aus der Quelle, kein uebernommener Code.
Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code