Skip to content

RDKEMW-13215: BtrCore_BTGetPairedDeviceInfo crash#48

Merged
DamianoBaroneSky merged 2 commits intordkcentral:developfrom
PreethiLakshmi91:develop
Mar 23, 2026
Merged

RDKEMW-13215: BtrCore_BTGetPairedDeviceInfo crash#48
DamianoBaroneSky merged 2 commits intordkcentral:developfrom
PreethiLakshmi91:develop

Conversation

@PreethiLakshmi91
Copy link
Copy Markdown

Reason for change: Crash and memleak fix - latest
Test Procedure: runbook test cases for bluetooth devices
Risks: Low
Priority: P1

@PreethiLakshmi91 PreethiLakshmi91 requested a review from a team as a code owner March 9, 2026 10:57
Copilot AI review requested due to automatic review settings March 9, 2026 10:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash/memory-leak scenario in the BlueZ5 DBus backend when fetching paired device info (BtrCore_BTGetPairedDeviceInfo), primarily by tightening NULL handling and adjusting DBus message lifecycle management.

Changes:

  • Added broader NULL checks (including pstlhBtIfce / pDBusConn) before issuing DBus calls.
  • Corrected DBus boolean parsing to use dbus_bool_t and added bounds/empty-path guards when collecting paired device paths.
  • Hardened DBus object cleanup by unref’ing and NULLing DBusMessage / DBusPendingCall pointers on more paths.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment on lines +4877 to +4879
if (i >= num) {
BTRCORELOG_INFO("num is: %d, i is %d\n", num, i);
}

This comment was marked as outdated.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment on lines +4955 to +4959
BTRCORELOG_INFO ("lpDBusReply is already NULL\n");
}
}
else {
BTRCORELOG_INFO ("lpDBusPendC is already NULL\n");

This comment was marked as outdated.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment on lines 4963 to 4967
if (i >= num) {
BTRCORELOG_INFO("2 - num is: %d, i is %d\n", num, i);
}


This comment was marked as outdated.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment on lines 4723 to 4734
dbus_error_init(&lDBusErr);
lpDBusReply = btrCore_BTSendMethodCall(pstlhBtIfce->pDBusConn, "/", DBUS_INTERFACE_OBJECT_MANAGER, "GetManagedObjects");
if (!lpDBusReply) {
BTRCORELOG_ERROR ("org.bluez.Manager.ListAdapters returned an error: '%s'\n", lDBusErr.message);
dbus_error_free(&lDBusErr);
if (dbus_error_is_set(&lDBusErr)) {
BTRCORELOG_ERROR ("GetManagedObjects returned an error: '%s'\n", lDBusErr.message);
dbus_error_free(&lDBusErr);
}
else {
BTRCORELOG_ERROR ("GetManagedObjects returned an error:unknown error\n");
}

return -1;
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

DBusError lDBusErr is initialized/checked here, but btrCore_BTSendMethodCall() (bluez5) does not take/return a DBusError, so lDBusErr will never be set for this call. This makes the dbus_error_is_set(&lDBusErr) branch effectively dead code and the resulting logging potentially misleading. Consider removing the DBusError handling here, or enhancing btrCore_BTSendMethodCall() / its callers to surface an actual error reason when GetManagedObjects fails.

Copilot uses AI. Check for mistakes.
Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
dbus_error_free(&lDBusErr);
}
else {
BTRCORELOG_ERROR ("GetManagedObjects returned an error:unknown error\n");

This comment was marked as outdated.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
return -1;
}

BTRCORELOG_INFO("Hitting BtrCore_BTGetPairedDeviceInfo\n");

This comment was marked as outdated.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment on lines +4811 to +4827
BTRCORELOG_INFO("device_prop changed from pointer to bool, %d\n", device_prop);
if ((adapter_path) && (adapter_path[0] != '\0') && (d < BT_MAX_NUM_DEVICE)) {
strncpy(&paths[d][0], adapter_path, (strlen(adapter_path) < BT_MAX_DEV_PATH_LEN) ? strlen(adapter_path) : BT_MAX_DEV_PATH_LEN - 1);
++d;
++d;
BTRCORELOG_INFO("path is copied for paired devices.\n");
}
else {
if (!adapter_path) {
BTRCORELOG_INFO("adapter_path is NULL\n");
}
else if (adapter_path[0] == '\0') {
BTRCORELOG_INFO("adapter_path string is empty\n");
}
else if (d >= BT_MAX_NUM_DEVICE) {
BTRCORELOG_WARN("Paired device list full; dropping extra entries\n");
}
}

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 4 comments.


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

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
Comment thread src/bt-ifce/btrCore_dbus_bluez5.c
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.


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

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
@PreethiLakshmi91 PreethiLakshmi91 force-pushed the develop branch 2 times, most recently from 4e80e57 to 1027b7d Compare March 23, 2026 09:26
Copilot AI review requested due to automatic review settings March 23, 2026 09:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 2 comments.


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

Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
if (!lpDBusReply) {
BTRCORELOG_ERROR ("org.bluez.Manager.ListAdapters returned an error: '%s'\n", lDBusErr.message);
dbus_error_free(&lDBusErr);
BTRCORELOG_ERROR ("GetManagedObjects returned an error:unknown error\n");
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The GetManagedObjects failure log message is misleading/low-signal: btrCore_BTSendMethodCall already logs the specific D-Bus error name when it receives an error reply, but this path always logs "unknown error" (and misses a space after the colon). Consider changing this to a generic "GetManagedObjects call failed" (or include the actual error name if available) to avoid confusing operators/debugging.

Suggested change
BTRCORELOG_ERROR ("GetManagedObjects returned an error:unknown error\n");
BTRCORELOG_ERROR ("GetManagedObjects call failed\n");

Copilot uses AI. Check for mistakes.
Comment thread src/bt-ifce/btrCore_dbus_bluez5.c Outdated
return -1;
}

dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &pdeviceInterface, DBUS_TYPE_INVALID);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

dbus_message_append_args returns a boolean indicating OOM/append failure, but its return value is ignored. If it fails, the method call is sent without required arguments and can lead to hard-to-debug failures. Capture the return value and, on failure, unref lpDBusMsg and return an error (similar to the send_with_reply failure path).

Suggested change
dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &pdeviceInterface, DBUS_TYPE_INVALID);
if (!dbus_message_append_args(lpDBusMsg, DBUS_TYPE_STRING, &pdeviceInterface, DBUS_TYPE_INVALID)) {
BTRCORELOG_ERROR ("Failed to append arguments to message ...\n");
dbus_message_unref(lpDBusMsg);
lpDBusMsg = NULL;
return -1;
}

Copilot uses AI. Check for mistakes.
Reason for change: Crash and memleak fix
Test Procedure: runbook test cases for bluetooth devices
Risks: Low
Priority: P1

Signed-off-by: ppalan289 <preethi_palanisamy@comcast.com>
Copilot AI review requested due to automatic review settings March 23, 2026 13:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 2 comments.


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

Comment on lines 4878 to 4885
if (!dbus_connection_send_with_reply(pstlhBtIfce->pDBusConn, lpDBusMsg, &lpDBusPendC, -1)) {
BTRCORELOG_ERROR ("failed to send message");
dbus_message_unref(lpDBusMsg);
lpDBusMsg = NULL;
return -1;
}

dbus_connection_flush(pstlhBtIfce->pDBusConn);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This loop dereferences pstlhBtIfce->pDBusConn without re-checking it. In earlier discussion it was noted the DBus connection may be changed externally; if pDBusConn can become NULL between the entry check and this send, this can reintroduce a crash. Consider re-validating pstlhBtIfce/pDBusConn immediately before use (or holding a stable reference under a lock) and failing gracefully if it’s gone.

Suggested change
if (!dbus_connection_send_with_reply(pstlhBtIfce->pDBusConn, lpDBusMsg, &lpDBusPendC, -1)) {
BTRCORELOG_ERROR ("failed to send message");
dbus_message_unref(lpDBusMsg);
lpDBusMsg = NULL;
return -1;
}
dbus_connection_flush(pstlhBtIfce->pDBusConn);
DBusConnection* pDBusConn = (pstlhBtIfce != NULL) ? pstlhBtIfce->pDBusConn : NULL;
if (pDBusConn == NULL) {
BTRCORELOG_ERROR("DBus connection is not available\n");
dbus_message_unref(lpDBusMsg);
lpDBusMsg = NULL;
return -1;
}
if (!dbus_connection_send_with_reply(pDBusConn, lpDBusMsg, &lpDBusPendC, -1)) {
BTRCORELOG_ERROR ("failed to send message");
dbus_message_unref(lpDBusMsg);
lpDBusMsg = NULL;
return -1;
}
dbus_connection_flush(pDBusConn);

Copilot uses AI. Check for mistakes.
Comment on lines 4722 to 4725
lpDBusReply = btrCore_BTSendMethodCall(pstlhBtIfce->pDBusConn, "/", DBUS_INTERFACE_OBJECT_MANAGER, "GetManagedObjects");
if (!lpDBusReply) {
BTRCORELOG_ERROR ("org.bluez.Manager.ListAdapters returned an error: '%s'\n", lDBusErr.message);
dbus_error_free(&lDBusErr);
BTRCORELOG_ERROR ("GetManagedObjects call failed\n");
return -1;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

btrCore_BTSendMethodCall() can leak the allocated DBusMessage when dbus_connection_send_with_reply() fails (it returns NULL without unref’ing the message). Since this function is used here for GetManagedObjects, the leak still exists on the failure path; consider fixing btrCore_BTSendMethodCall() to always unref lpDBusMsg before returning, even on send failure.

Copilot uses AI. Check for mistakes.
@DamianoBaroneSky DamianoBaroneSky merged commit f0507ce into rdkcentral:develop Mar 23, 2026
9 of 10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants