fix: handle zero-sized and undersized temp buffers in buffered JSON dump - #175
Merged
rgerhards merged 2 commits intoJul 23, 2026
Merged
Conversation
rgerhards
force-pushed
the
codex/propose-fix-for-json-dumping-vulnerability
branch
from
July 23, 2026 11:25
94db948 to
5d416b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
vsnprintf()and reuse a consumedva_list.Description
buffer_printf()check the actual available space (available = buffer->size - buffer->filled) and skip callingvsnprintf()whenavailable == 0, forcing the code path that uses a dynamically allocated buffer instead.va_list(va_start/va_end) so a consumedva_listis not reused.availablefor success comparisons and updatebuffer->filled(notbuffer->size) when writing retry data into the buffer.buffer_flush()whenbuffer->filled > 0.fjson_object_dump_buffered()may be called withtemp == NULLwhensize == 0.tests/test_dump_buffered.{c,test,expected}) and register it intests/Makefile.amto cover bothsize == 0and a very small nonzerosizecases.Testing
tests/test_dump_buffered.expectedusinggccand a localconfig.h(test passed).-fsanitize=address,undefined) and observed no sanitizer errors and expected output (test passed).git diff --checkto ensure no whitespace or diff issues (passed).autoreconf -fi && ./configure && make checkcould not be executed in this environment becauseaclocalis not available (tooling limitation).Codex Task
Summary by cubic
Safely handle zero-sized and undersized temp buffers in the buffered JSON dump to prevent out-of-bounds writes and undefined behavior. Falls back to dynamic allocation when needed and adds a regression test.
vsnprintf()when available space is 0; force dynamic buffer path.va_listfor each formatting attempt.available = size - filledfor checks; updatebuffer->filledon retries.buffer->filled > 0to avoid empty-buffer flushes.tempmay beNULLwhensize == 0infjson_object_dump_buffered().test_dump_bufferedcoveringsize == 0and tiny nonzero buffers; register intests/Makefile.amand includetest_dump_buffered.expectedinEXTRA_DIST.Written for commit 2e0085a. Summary will update on new commits.