Add BUFFER_FIELD macro for safe pretty-printing of flexible array members#40273
Merged
Add BUFFER_FIELD macro for safe pretty-printing of flexible array members#40273
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens message PrettyPrint() output for structs that use flexible array members (e.g., char Buffer[] / char Content[]) by preventing unbounded C-string reads and instead printing a length-bounded view derived from Header.MessageSize.
Changes:
- Add
BUFFER_FIELD(Name)plusPrettyPrintSafeBufferView()to safely pretty-print flexible array members usingstrnlenandHeader.MessageSizebounds. - Extend the
PrettyPrinttemplate to handlestd::string_view. - Update affected message structs in
lxinitshared.hto useBUFFER_FIELDinstead ofFIELDfor flexible buffers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/shared/inc/prettyprintshared.h |
Introduces bounded buffer pretty-print helper + macro, and adds std::string_view printing support. |
src/shared/inc/lxinitshared.h |
Switches flexible-array fields in message structs to the new safe BUFFER_FIELD pretty-printing. |
OneBlue
previously approved these changes
Apr 22, 2026
…bers Message structs with flexible array members (char Buffer[], char Content[]) used FIELD() in PRETTY_PRINT, which streams the member as a C-string until a NUL byte. Add a BUFFER_FIELD macro and PrettyPrintSafeBufferView helper that bounds the read using Header.MessageSize. Also add std::string_view handling to PrettyPrint. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
40f495b to
a5995ed
Compare
OneBlue
approved these changes
Apr 22, 2026
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.
Message structs with flexible array members (
char Buffer[],char Content[]) usedFIELD()inPRETTY_PRINT, which streams the member as a C-string until a NUL byte is encountered. If the buffer happens to not be NUL-terminated (e.g. due to a truncated or malformed message), this could read past the intended bounds.This PR adds:
BUFFER_FIELD(Name)macro that computes safe bounds fromHeader.MessageSizePrettyPrintSafeBufferViewhelper that caps reads usingstrnlenstd::string_viewbranch in thePrettyPrinttemplatelxinitshared.hto useBUFFER_FIELDThis matches the existing pattern in
LX_GNS_RESULTwhich already excluded itsBufferfromPRETTY_PRINTwith the comment: 'Buffer' doesn't always contain a string, so don't pretty print it.