Skip to content

Conversation

@svc-rdkeportal01
Copy link

Issue Fixed

Coverity Defect: CHECKED_RETURN
CWE: CWE-252 (Unchecked Return Value)
Severity: Medium
Function: rbus_close
File: src/rbus/rbus.c

Root Cause

The function rbus_close() calls remove() to delete a temporary file (/tmp/.rbus/<pid>_<componentId>) but does not check the return value. This could mask failures in file deletion, potentially leading to:

  • Accumulated temporary files if deletion consistently fails
  • Undetected permission issues
  • Disk space issues going unnoticed

Changes Made

Added return value check for remove() with error logging:

int removeRet = remove(filename);
if(removeRet != 0 && errno != ENOENT)
{
    RBUSLOG_ERROR("remove(%s) failed with error %d", filename, errno);
}

Key points:

  • Captures return value in removeRet
  • Checks if removal failed (removeRet != 0)
  • Ignores ENOENT (file doesn't exist) as this is not an error condition
  • Logs actual errors with filename and errno for debugging

Also added #include <errno.h> to access errno.

Why This Fix is Correct

  1. Detects real failures - Logs when file removal fails for actual errors
  2. Ignores expected cases - ENOENT is not logged (file may not exist)
  3. Aids debugging - Error message includes filename and errno
  4. No functional change - Only adds logging, doesn't change behavior
  5. Matches best practices - Checking system call return values is standard

Testing

  • Verified fix compiles without errors
  • Checked that errno is properly included
  • Confirmed error logging only triggers on actual failures

The function rbus_close() calls remove() to delete a temporary file but
does not check the return value. This could mask failures in file deletion.

This fix captures the return value and logs an error if the removal fails
for any reason other than the file not existing (ENOENT).

Coverity: CHECKED_RETURN
CWE-252: Unchecked Return Value
@svc-rdkeportal01 svc-rdkeportal01 requested a review from a team as a code owner December 4, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant