Fix #2417, add size check in CFE_MSG_Init#2694
Open
heathdutton wants to merge 1 commit into
Open
Conversation
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.
Checklist (Please check before submitting)
Describe the contribution
Fixes #2417
CFE_MSG_Initonly NULL-checksMsgPtr, then callsCFE_MSG_InitDefaultHdrandCFE_MSG_SetMsgIdbeforeCFE_MSG_SetSizeperforms any size validation. If the caller passesSizesmaller than the header, those earlier calls have already written out-of-bounds by the timeSetSizereturnsCFE_MSG_BAD_ARGUMENT.Extended the existing guard to also reject
Size < sizeof(*MsgPtr). Usingsizeof(*MsgPtr)naturally covers both the pri-only (6 bytes) and priext (10 bytes) header configurations without any ifdef.Testing performed
Added one assertion in
test_cfe_msg_init.cforSize = sizeof(CFE_MSG_Message_t) - 1, exercising the new branch. The pre-existingSize = 0assertion also now exits via this guard instead of coincidentally viaSetSize.clang-format --dry-run --Werrorclean.Expected behavior changes
Callers passing a buffer smaller than the CCSDS header will now receive
CFE_MSG_BAD_ARGUMENTwith no writes to the buffer. Previously the same callers receivedCFE_MSG_BAD_ARGUMENTbut only after the function had already corrupted memory past the end of their buffer. The downstreamSetSizerange check (Size < CFE_MSG_SIZE_OFFSETand upper bound) is unchanged.The related downstream bug in CF (nasa/CF#401) that relied on this behavior is already closed.
System(s) tested on
Code review and clang-format only (macOS does not support cFS native build). Upstream CI will exercise the unit tests on Linux.
Contributor Info
Heath Dutton / Personal