Repository navigation
RDKEMW-26485: Fix Coverity defects (7 files) - #91
Closed
rdkdevpilot wants to merge 8 commits into
Closed
rdkdevpilot wants to merge 8 commits into
rdkdevpilot wants to merge 8 commits into
Conversation
Defect ID: 94bafbe6-bafc-4589-ad71-0dd4390aeb49
Defect ID: ecbd428a-e53f-4374-aac8-291f83795f10
Defect ID: d3d36774-e66d-4270-a20f-ea0b73848ca7
Defect ID: 9e9a9a4c-44db-4277-b0ad-77be6d088e1b
Defect ID: 02eb5c8a-2c6e-4b46-a6d5-480416ac5b1c
Defect ID: 1dd4d01a-823e-468e-a5e9-72e72f662f9f
Defect ID: a70f1faf-76f9-41cf-a59a-3d43dcc667a1
There was a problem hiding this comment.
🟡 Changes recommended
Uptime conversion remains unsafe, and the cleanup traversal still contains an exploitable TOCTOU race.
3 open findings
What changed in this PR
Addresses Coverity findings across crash processing, rate limiting, cleanup, and platform utilities.
Changes:
- Corrects buffer sizing and overlapping copies.
- Reorders bounds checks and removes redundant file existence checks.
- Adds input validation and symlink-aware cleanup.
| File | Description |
|---|---|
c_sourcecode/src/main.c |
Corrects archive initialization size. |
c_sourcecode/src/utils/prerequisites.c |
Adds uptime range validation. |
c_sourcecode/src/ratelimit/ratelimit.c |
Reorders bounds checks and removes pre-open stat. |
c_sourcecode/src/scanner/scanner.c |
Corrects container-name copy bound. |
c_sourcecode/src/archive/archive.c |
Uses overlap-safe memmove. |
c_sourcecode/src/platform/platform.c |
Removes a redundant sanitization call. |
c_sourcecode/src/utils/cleanup_batch.c |
Uses lstat during recursive cleanup. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| snprintf(path, sizeof(path), "%s/%s", working_dir, entry->d_name); | ||
|
|
||
| if (stat(path, &st) < 0) | ||
| if (lstat(path, &st) < 0) |
Comment on lines
91
to
+93
| if (NULL != (fgets(pEstbMac, szBufSize, fp))) | ||
| { // better be a valid string on first line | ||
| i = stripinvalidchar(pEstbMac, szBufSize); | ||
| } | ||
| } |
Comment on lines
64
to
+66
| int uptime_val = (int)uptime_seconds; | ||
|
|
||
| if (uptime_val < FOUR_EIGHTY_SECS) | ||
| if (uptime_val < FOUR_EIGHTY_SECS && uptime_val >= 0) |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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: dev-user
Fixed Files
c_sourcecode/src/main.cc_sourcecode/src/utils/prerequisites.cc_sourcecode/src/ratelimit/ratelimit.cc_sourcecode/src/scanner/scanner.cc_sourcecode/src/archive/archive.cc_sourcecode/src/platform/platform.cc_sourcecode/src/utils/cleanup_batch.cFix Summaries
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.
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 or integer overflow when passed tosleep(). The added&& uptime_val >= 0check clamps the tainted input to a valid range before use. The fix is minimal (one condition change), does not introduce new defects, preserves all existing logic and branches, and correctly handles the error path (the block is simply skipped for negative values). The whitespace-only changes inside the block are cosmetic and do not affect behavior.c_sourcecode/src/ratelimit/ratelimit.cThe fix correctly addresses the TOCTOU defect in is_recovery_time_reached() by removing the stat() call that checked file existence before fopen(), and instead relying on fopen() itself to atomically report file absence. This eliminates the window between the stat() check and the subsequent fopen() where the file could be created or deleted by another process. The struct stat variable is also correctly removed since it is no longer used. The two loop condition reorderings (checking i < sizeof(...) before dereferencing the array) are correct safety improvements that prevent potential out-of-bounds reads if the buffer is not null-terminated. All changes are minimal, targeted, and do not break any existing logic or introduce new defects.
c_sourcecode/src/scanner/scanner.cThe fix correctly changes the cap on
pnamelenfromsizeof(ProcessName)(512) tosizeof(containerName)(256). Sincepnamelenis computed asus - containerNamewhereusis a pointer intocontainerName[256], the correct upper bound issizeof(containerName) - 1 = 255. The original check againstsizeof(ProcessName)(512) was too permissive and could allowpnamelento exceed the source buffer size in thememcpy. The fix is minimal, correct, and does not break any existing logic.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 = 5, so the source starts 4 bytes ahead of the destination — clearly overlapping).strcpyhas undefined behavior on overlapping buffers.memmoveis the correct replacement as it explicitly handles overlapping memory regions safely. 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/platform/platform.cThe fix correctly addresses the UNUSED_VALUE defect by removing the unused assignment at line 93. The original code assigned the return value of stripinvalidchar() to variable 'i' inside the if block (line 93), but this value was immediately overwritten by another call to stripinvalidchar() at line 96, making the first assignment unused. The fix removes the redundant assignment while preserving the call to stripinvalidchar() at line 96, which is used in the subsequent condition check at line 100. The logic flow remains intact: fgets() is still called, the file is closed, stripinvalidchar() processes the buffer once, and the result is properly used. No new defects are introduced.
c_sourcecode/src/utils/cleanup_batch.cThe fix correctly addresses the defect by changing stat() to lstat() on line 531. This change prevents following symbolic links when checking file status in remove_pending_dumps(), which is the appropriate behavior for a recursive directory cleanup function. The fix is minimal (single function call change), preserves all existing logic, and aligns with the pattern already used in walk_dir_recursive() at line 186. No new defects are introduced, and the change is functionally correct for handling symbolic links safely during directory traversal.