Skip to content

Conversation

@svc-rdkeportal01
Copy link

Issue Fixed

Coverity Defect: UNREACHABLE
CWE: CWE-561 (Dead Code)
Severity: Medium
Function: rbus_open
File: src/rbus/rbus.c

Root Cause

The function rbus_open has unreachable code after a return statement:

RBUSLOG_INFO(" rbus open (%s) success", componentName);
return RBUS_ERROR_SUCCESS;

// ❌ UNREACHABLE: This code can never be executed!
if((err = rbus_unregisterObj(componentName)) != RBUSCORE_SUCCESS)
    RBUSLOG_ERROR("(%s): unregisterObj error %d", componentName, err);

exit_error2:
    // ... more cleanup

The rbus_unregisterObj cleanup code is placed after the return statement, making it impossible to reach. Additionally, when rbusHandle_TimeoutValuesInit fails, it does goto exit_error2, which skips this cleanup entirely.

Changes Made

1. Added new error label exit_error3:

return RBUS_ERROR_SUCCESS;

exit_error3:  // ✅ New label makes code reachable

if((err = rbus_unregisterObj(componentName)) != RBUSCORE_SUCCESS)
    RBUSLOG_ERROR("(%s): unregisterObj error %d", componentName, err);

exit_error2:

2. Changed goto target:

if (rbusHandle_TimeoutValuesInit(tmpHandle) != 0)
{
    RBUSLOG_ERROR("(%s): rbusHandle_TimeoutValuesInit failed", componentName);
    goto exit_error3;  // ✅ Changed from exit_error2
}

Why This Fix is Correct

  1. Makes code reachable - The cleanup code can now be executed via goto
  2. Proper error handling - When TimeoutValuesInit fails, it properly unregisters the object
  3. Maintains cleanup order - Error labels cascade properly: exit_error3 → exit_error2 → exit_error1 → exit_error0
  4. Simple fix - Just adds a label and changes one goto target

Error Handling Flow

Before (Buggy):

TimeoutValuesInit fails → goto exit_error2 → skips rbus_unregisterObj

After (Fixed):

TimeoutValuesInit fails → goto exit_error3 → calls rbus_unregisterObj → falls through to exit_error2

Testing

  • Verified fix compiles without errors
  • Checked that error handling flow is correct
  • Confirmed cleanup code is now reachable

The function rbus_open has unreachable code after the return statement.
The rbus_unregisterObj cleanup code can never be executed because it
comes after 'return RBUS_ERROR_SUCCESS'.

This fix adds a new error label 'exit_error3' and changes the goto
statement to jump to this label instead of exit_error2, making the
cleanup code reachable.

Coverity: UNREACHABLE
CWE-561: Dead Code
@svc-rdkeportal01 svc-rdkeportal01 requested a review from a team as a code owner December 4, 2025 20:11
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