Repository navigation
nul-terminate bin/ext output in msgpack_object_print_buffer - #1196
Merged
Merged
Conversation
msgpack_object_bin_print_buffer copied printable bytes with memcpy and never wrote a terminator, unlike the snprintf calls around it. When a bin or ext payload filled the buffer, msgpack_object_print_buffer returned 0 with no NUL anywhere in the buffer, so a caller printing it with %s (as example/user_buffer_unpack.c does) read past the end. Stop one byte short and terminate the buffer, matching snprintf truncation. Return values are unchanged.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## c_master #1196 +/- ##
============================================
+ Coverage 57.47% 58.74% +1.26%
============================================
Files 10 10
Lines 1124 1144 +20
Branches 129 140 +11
============================================
+ Hits 646 672 +26
+ Misses 478 472 -6 🚀 New features to boost your workflow:
|
Contributor
|
@rajath201 thank you for sending the PR. It looks good to me. |
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.
msgpack_object_bin_print_buffercopies printable bin/ext bytes withmemcpyand never writes a terminator, unlike thesnprintfcalls around it. When a payload fills the buffer,msgpack_object_print_bufferreturns 0 with no NUL anywhere in it, so a caller that logs the result with%s(asexample/user_buffer_unpack.cdoes) reads past the end. A 6-bytebin8 "test"off the wire printed into a 5-byte buffer trips ASan with a stack-buffer-overflow instrlen.Keep one byte back in the printable branch and terminate on truncation, the same contract every other type already gets from
snprintf. Return values don't change for any input. The cost is one extra byte store per character, nothing measurable. The newobject_bin_print_buffer_overflow_terminatedtest fails on the current tree and passes with the fix, and ctest is 6/6 under ASan/UBSan.