Skip to content

RDKEMW-12176: btrCore_PopulateListOfPairedCrash_p#75

Open
PreethiALPI wants to merge 1 commit into
rdkcentral:developfrom
PreethiALPI:RDKEMW-12176_a1
Open

RDKEMW-12176: btrCore_PopulateListOfPairedCrash_p#75
PreethiALPI wants to merge 1 commit into
rdkcentral:developfrom
PreethiALPI:RDKEMW-12176_a1

Conversation

@PreethiALPI

Copy link
Copy Markdown

Reason for change: Crash fix
Test Procedure: Device deepsleep causing the crash
Risks: Low
Priority: P2

@PreethiALPI PreethiALPI requested a review from a team as a code owner June 22, 2026 10:14
Copilot AI review requested due to automatic review settings June 22, 2026 10:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a crash during teardown (e.g., deep sleep) by adding teardown-awareness to btrCore and updating unit tests to validate termination behavior.

Changes:

  • Add a global “terminating” flag and per-handle generation tracking to reduce UAF risk during teardown.
  • Harden service-data copying by clamping advertised service-data length to the destination buffer size.
  • Update/extend unit tests to initialize generation and assert termination behavior across DeInit scenarios.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/btrCore.c Adds termination/generation tracking and a termination guard in paired-device population; clamps service-data copy length.
include/btrCore.h Exposes UNIT_TEST-only helpers for generation/termination inspection.
unitTest/test_btrCore.c Updates tests to set generation, resets terminator where needed, and adds DeInit termination tests.
Comments suppressed due to low confidence (1)

src/btrCore.c:1226

  • The trace loop iterates using the source service-data length, but reads from the destination buffer (pcData) which is clamped to BTRCORE_MAX_SERVICE_DATA_LEN. If saServices[count].len exceeds the max, this will read past the end of pcData (OOB read) during logging.
            for (int i =0; i < apstBTDeviceInfo->saServices[count].len; i++){
                BTRCORELOG_TRACE ("ServiceData[%d] = [%x]\n ", i, lstFoundDevice.stAdServiceData[count].pcData[i]);
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/btrCore.c
Comment on lines +298 to +301
void btrCore_ResetTerminatorForTest(void) {
g_atomic_int_set(&gIsBtrCoreTerminating, 0);
gint val = g_atomic_int_get(&gIsBtrCoreTerminating);
}
Comment thread src/btrCore.c
Comment on lines +303 to +306
void btrCore_SetTerminatorForTest(void) {
g_atomic_int_set(&gIsBtrCoreTerminating, 1);
gint val = g_atomic_int_get(&gIsBtrCoreTerminating);
}
Comment thread unitTest/test_btrCore.c
@@ -4171,6 +4350,7 @@ void test_BTRCore_SetAdvertisementInfo_NullAdvtType(void) {
tBTRCoreHandle hBTRCore = (tBTRCoreHandle)1; // Mock handle
char advtBeaconName[] = "BeaconName";

/* Invalid handle value - should never be deferenced */
Reason for change: Crash fix
Test Procedure: Device deepsleep causing the crash
Risks: Low
Priority: P2

Signed-off-by: ppalan289 <preethi_palanisamy@comcast.com>
Copilot AI review requested due to automatic review settings July 8, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/btrCore.c
Comment on lines +1518 to +1522
/* Prevent UAF when worker threads run during teardown */
if(g_atomic_int_get(&gIsBtrCoreTerminating)) {
BTRCORELOG_WARN("btrCore: Ignoring PopulateListOfPairedDevices during termination\n");
return enBTRCoreFailure;
}
Comment thread src/btrCore.c
Comment on lines +298 to +301
void btrCore_ResetTerminatorForTest(void) {
g_atomic_int_set(&gIsBtrCoreTerminating, 0);
gint val = g_atomic_int_get(&gIsBtrCoreTerminating);
}
Comment thread src/btrCore.c
Comment on lines +303 to +306
void btrCore_SetTerminatorForTest(void) {
g_atomic_int_set(&gIsBtrCoreTerminating, 1);
gint val = g_atomic_int_get(&gIsBtrCoreTerminating);
}
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.

3 participants