fix: replace unsafe strcpy with memcpy in CFE_Assert and CFE_TBL#2760
Open
stark256-spec wants to merge 1 commit into
Open
fix: replace unsafe strcpy with memcpy in CFE_Assert and CFE_TBL#2760stark256-spec wants to merge 1 commit into
stark256-spec wants to merge 1 commit into
Conversation
Static analyzer flagged two unbounded strcpy calls (issue nasa#2737): 1. cfe_assert_init.c (CFE_Assert_OpenLogFile): strcpy was used to append ".tmp" to the log filename. The preceding bounds check ensures at least 5 bytes of space remain, so replace with memcpy(dst, ".tmp", 5) which copies the 4-char suffix plus null terminator explicitly. 2. cfe_tbl_internal.c (CFE_TBL_MarkNameAsModified): strcpy was used to append "(*)" to the table name. The preceding bounds check ensures at least 4 bytes remain, so replace with memcpy(dst, "(*)", 4) which copies the 3-char suffix plus null terminator explicitly. Both replacements are semantically identical but eliminate the unsafe unbounded copy pattern flagged by static analysis. Fixes nasa#2737
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.
Summary
Fixes #2737
Static analyzer flagged two unbounded
strcpycalls that should use a bounded alternative.CFE_Assert_OpenLogFile (cfe_assert_init.c)
strcpywas used to append.tmpto the log filename. The preceding bounds check already ensures at least 5 bytes of space remain in the buffer, so replace withmemcpy(dst, ".tmp", 5)to copy the 4-character suffix plus null terminator explicitly.CFE_TBL_MarkNameAsModified (cfe_tbl_internal.c)
strcpywas used to append(*)to the table name. The preceding calculation already ensures at least 4 bytes remain atEndPtr, so replace withmemcpy(dst, "(*)", 4)to copy the 3-character suffix plus null terminator explicitly.Both replacements are semantically identical to the original code — the bounds are already enforced by the surrounding logic — but eliminate the unsafe unbounded copy pattern.
Test plan