Skip to content

Bluetooth: TBS: Fix TBS API accessing NULL inst #90613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Thalley
Copy link
Collaborator

@Thalley Thalley commented May 26, 2025

Some TBS API functions attempted to take the mutex of an instance before the NULL check.

Reorder the checks of the functions, and also modify function to be more similar (using the same terms and structure).

fixes #90552
fixes #90527

@Thalley Thalley requested a review from Copilot May 26, 2025 14:55
Copy link

@Copilot 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

This PR fixes an issue in the TBS API where a mutex was accessed on a NULL instance, and it standardizes the control flow for error checking across several TBS functions. Key changes include:

  • Reordering the NULL-check to occur before taking the mutex.
  • Replacing the local variable “status” with “ret” for storing return values.
  • Standardizing function structure and logging messages across the API.

@Thalley Thalley force-pushed the tbs_null_pointer_fix branch from 566b050 to 98d9ad1 Compare May 26, 2025 14:59
@Thalley Thalley requested a review from Copilot May 26, 2025 15:11
Copy link

@Copilot 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

This PR ensures TBS API functions check for a NULL instance before taking the mutex and unifies the variable names/structure across those functions.

  • Reordered NULL checks ahead of k_mutex_lock in all TBS API calls
  • Replaced status with ret and made struct initializers use a consistent braced layout
  • Added LOG_DBG messages for lookup failures
Comments suppressed due to low confidence (2)

subsys/bluetooth/audio/tbs.c:2525

  • In bt_tbs_join, the count passed to join_calls should be clamped to CONFIG_BT_TBS_MAX_CALLS (e.g., MIN(call_index_cnt, CONFIG_BT_TBS_MAX_CALLS)) to match the earlier memcpy and avoid out-of-bounds processing.
ret = join_calls(inst, ccp, call_index_cnt);

subsys/bluetooth/audio/tbs.c:2502

  • [nitpick] For consistency with the rest of the TBS API, consider returning a TBS-specific result code (e.g., BT_TBS_RESULT_CODE_INVALID_CALL_INDEX or a dedicated invalid-parameter code) instead of a raw -EINVAL.
return -EINVAL;

Some TBS API functions attempted to take the mutex
of an instance before the NULL check.

Reorder the checks of the functions, and also modify function
to be more similar (using the same terms and structure).

Signed-off-by: Emil Gydesen <[email protected]>
@Thalley Thalley force-pushed the tbs_null_pointer_fix branch from 2b262ba to 7f651cf Compare July 1, 2025 12:23
Copy link

sonarqubecloud bot commented Jul 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Review
1 participant