Repository navigation
coverity_integration_2: Fix Coverity defects (3 files) Severity [Medium] - #93
Open
rdkdevpilot wants to merge 3 commits into
Open
rdkdevpilot wants to merge 3 commits into
rdkdevpilot wants to merge 3 commits into
Conversation
Defect ID: 02eb5c8a-2c6e-4b46-a6d5-480416ac5b1c
Defect ID: ecbd428a-e53f-4374-aac8-291f83795f10
Defect ID: 94bafbe6-bafc-4589-ad71-0dd4390aeb49
There was a problem hiding this comment.
🟢 Approval recommended
The three fixes are narrow and consistent with their intended behavior, with no unresolved findings.
No open issues 🎉
What changed in this PR
This PR addresses three Coverity defects in the crash-upload code with narrowly scoped fixes to memory copying, initialization, and upload-delay validation.
Changes:
- Use
memmovefor overlapping filename buffers. - Reject negative uptime values before calculating the upload delay.
- Use the structure size when zeroing the archive array.
| File | Description |
|---|---|
c_sourcecode/src/utils/prerequisites.c |
Adds a nonnegative uptime guard before deferring uploads. |
c_sourcecode/src/main.c |
Corrects the element size used to initialize the archive array. |
c_sourcecode/src/archive/archive.c |
Safely copies overlapping filename data, including the null terminator. |
Review effort: Balanced
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.
Automated Fix for Coverity Defects
Triggered by: GomathiShankar PS
Fixed Files
c_sourcecode/src/archive/archive.cc_sourcecode/src/utils/prerequisites.cc_sourcecode/src/main.cFix Summaries
c_sourcecode/src/archive/archive.cThe fix correctly replaces
strcpy(tmp + 1, tmp + pattern_len)withmemmove(tmp + 1, tmp + pattern_len, strlen(tmp + pattern_len) + 1). The original code usedstrcpyon overlapping memory regions (sourcetmp + pattern_lenand destinationtmp + 1both point into the same buffernew_dump_name, withpattern_len = 5meaning the source is 4 bytes ahead of the destination — clearly overlapping).strcpyhas undefined behavior on overlapping buffers.memmoveis the correct POSIX function for overlapping memory copies. The byte countstrlen(tmp + pattern_len) + 1correctly copies the tail of the string including the null terminator. The fix is minimal (single line change), does not introduce any new defects, preserves the existing loop logic, and directly addresses the Coverity BUFFER_SIZE / overlapping buffer defect.c_sourcecode/src/utils/prerequisites.cThe fix correctly addresses the TAINTED_SCALAR defect by adding a
uptime_val >= 0guard to the condition on line 66. The valueuptime_valis derived fromfscanfreading an external file (/proc/uptimeor/opt/uptime), making it tainted. Without the guard, a negativeuptime_val(e.g., from a malformed file) would pass the< FOUR_EIGHTY_SECScheck and causesleep_time = FOUR_EIGHTY_SECS - uptime_valto produce a very large positive integer, potentially causing an extremely long sleep. The addeduptime_val >= 0check prevents this. The fix is minimal (one condition change), does not introduce new defects, preserves all existing logic and branches, and correctly validates the tainted scalar before use.c_sourcecode/src/main.cThe fix correctly addresses the SIZEOF_MISMATCH defect by changing sizeof(archive) to sizeof(*archive). The original code used sizeof on the pointer variable 'archive' (which would be the size of a pointer, typically 4 or 8 bytes), while the corrected code uses sizeof(*archive) to get the size of the archive_info_t structure that the pointer points to. This ensures memset correctly zeroes out the entire allocated array of archive_info_t structures. The fix is minimal, correct, and does not introduce any new defects or break existing logic.