Skip to content

guard zero-size memcpy/memcmp in v4raw_ref and the carray adaptors - #1239

Open
rajath201 wants to merge 1 commit into
msgpack:cpp_masterfrom
rajath201:adaptor-empty-payload-null-ptr
Open

rajath201 wants to merge 1 commit into
msgpack:cpp_masterfrom
rajath201:adaptor-empty-payload-null-ptr

Conversation

@rajath201

Copy link
Copy Markdown

64473c2 fixed the null data pointer of an empty str or bin reaching memcpy and memcmp in object.hpp's copy and equality visitors, but the v1 adaptors still pass it through. a0 (fixstr, length 0) decodes to via.str.ptr == MSGPACK_NULLPTR, so comparing two v4raw_ref values calls memcmp with null arguments, and converting an empty str or bin into char[N], unsigned char[N], std::array<char, N>, std::array<unsigned char, N> or std::byte[N] calls memcpy with a null source. With MSGPACK_DEFAULT_API_VERSION=1 the v1 unpack_str/unpack_bin report every zero-length str and bin that way, so the bin branches are reachable too; glibc declares both functions __nonnull((1,2)) and the CI job builds with -fno-sanitize-recover=all, so a test that walked these paths aborts the build rather than just warning.

The guard sits next to each call, in the form raw_ref and the vector_char/vector_unsigned_char/vector_byte adaptors already use, so callers don't each need to special case an empty payload before converting or comparing. Non-empty payloads are untouched: the length is still checked against N first and the trailing NUL is still written when size < N. The two new cases in test/security_fixes_cpp11.cpp abort under UBSan on the current tree (null pointer passed as argument 2, which is declared to never be null at carray.hpp:50) and pass with the fix; the full suite stays green (42/42) at API versions 1 and 3 with -Werror -g -fsanitize=undefined -fno-sanitize-recover=all.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.40%. Comparing base (39cc081) to head (c5d3461).
⚠️ Report is 64 commits behind head on cpp_master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff               @@
##           cpp_master    #1239      +/-   ##
==============================================
- Coverage       85.36%   80.40%   -4.97%     
==============================================
  Files              80       80              
  Lines            5099     5859     +760     
  Branches          507      656     +149     
==============================================
+ Hits             4353     4711     +358     
- Misses            746     1148     +402     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants