rbus: fixup null pointer dereference in rbusEvent_SubscribeExRawData#411
Open
svc-rdkeportal01 wants to merge 4 commits intodevelopfrom
Open
rbus: fixup null pointer dereference in rbusEvent_SubscribeExRawData#411svc-rdkeportal01 wants to merge 4 commits intodevelopfrom
svc-rdkeportal01 wants to merge 4 commits intodevelopfrom
Conversation
Fixes Coverity CID 87 Generated by RDKDevPilot AI Bot Root Cause: rbusEventSubscription_find() can return NULL at lines 5623 and 5649, but subInternal is dereferenced at lines 5641 and 5659 without NULL check. This can cause a crash if the subscription is not found. Changes: - Add NULL check after rbusEventSubscription_find() at line 5632 - Add NULL check after rbusEventSubscription_find() at line 5650 - Log error and return RBUS_ERROR_INVALID_STATE if subInternal is NULL - Wrap AddPrivateListener and AddListener calls in else blocks Impact: - Prevents NULL pointer dereference crash - Provides clear error logging when subscription not found - Returns appropriate error code to caller Bot Validation: 95/100
Fix unit test failures by properly handling the error case when subInternal is NULL. This matches the pattern used when rbusEvent_SubscribeWithRetries fails (lines 5616-5624). Changes: - Unlock mutex before breaking (prevent deadlock) - Break loop immediately (fail fast) - Remove else blocks (code executes only if subInternal is valid) This ensures the function fails fast when subscription lookup fails, rather than continuing with remaining subscriptions and returning an error at the end.
Revert to the approved pattern from PR #370: - Add NULL check with else block - Set errorcode but don't break - Let loop continue with remaining subscriptions - Mutex unlocks normally at end of iteration This prevents double mutex unlock and matches the pattern used in rbusEvent_SubscribeRawData (PR #370, merged).
Fix compilation error by using the correct error constant. RBUS_ERROR_INVALID_STATE does not exist in rbusError_t enum. Use RBUS_ERROR_INVALID_INPUT instead, matching the pattern from PR #370 which fixed the same issue in rbusEvent_SubscribeRawData. Fixes compilation error: error: 'RBUS_ERROR_INVALID_STATE' undeclared did you mean 'RBUSCORE_ERROR_INVALID_STATE'?
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.
Fix NULL_RETURNS in rbusEvent_SubscribeExRawData
Issues Fixed
src/rbus/rbus.cat lines 5644 and 5655Root Cause
rbusEventSubscription_find()can return NULL, but the returned pointersubInternalis dereferenced without NULL checks at:rbusMessage_AddPrivateListener(..., (void *)(subInternal->sub), subInternal->subscriptionId)rbusMessage_AddListener(..., (void *)(subInternal->sub), subInternal->subscriptionId)This can cause a NULL pointer dereference if the subscription lookup fails.
Changes Made
Added NULL checks before dereferencing
subInternalin two locations within theelseblock (after successfulrbusEvent_SubscribeWithRetries):Location 1 (myConn path):
Location 2 (no myConn path):
Pattern Match
This fix follows the exact pattern from PR #370 (merged by Permanence AI) which fixed the same issue in
rbusEvent_SubscribeRawData:errorcode = RBUS_ERROR_INVALID_INPUT