All of lore.kernel.org
 help / color / mirror / Atom feed
From: Iulia Tanasescu <iulia.tanasescu@nxp.com>
To: linux-bluetooth@vger.kernel.org
Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com,
	andrei.istodorescu@nxp.com, luiz.dentz@gmail.com,
	Iulia Tanasescu <iulia.tanasescu@nxp.com>
Subject: [PATCH BlueZ 3/3] bass: Add checks for bap user data
Date: Thu, 20 Feb 2025 10:58:11 +0200	[thread overview]
Message-ID: <20250220085811.5033-4-iulia.tanasescu@nxp.com> (raw)
In-Reply-To: <20250220085811.5033-1-iulia.tanasescu@nxp.com>

This adds checks before parsing bt_bap user data in bap attached/detached,
to avoid accessing NULL pointers in case the user data has been cleared
or has not been set before attaching a BAP session.
---
 profiles/audio/bass.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index 6c84fa1c3..67ee847b8 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -559,14 +559,21 @@ static void confirm_cb(GIOChannel *io, void *user_data)
 
 static void bap_attached(struct bt_bap *bap, void *user_data)
 {
-	struct btd_service *service = bt_bap_get_user_data(bap);
-	struct btd_device *device = btd_service_get_device(service);
-	struct btd_adapter *adapter = device_get_adapter(device);
+	struct btd_service *service;
+	struct btd_device *device;
+	struct btd_adapter *adapter;
 	struct bass_delegator *dg;
 	GError *err = NULL;
 
 	DBG("%p", bap);
 
+	service = bt_bap_get_user_data(bap);
+	if (!service)
+		return;
+
+	device = btd_service_get_device(service);
+	adapter = device_get_adapter(device);
+
 	dg = queue_find(delegators, delegator_match_device, device);
 	if (!dg)
 		/* Only probe devices added via Broadcast Assistants */
@@ -620,12 +627,18 @@ static void setup_free(void *data)
 
 static void bap_detached(struct bt_bap *bap, void *user_data)
 {
-	struct btd_service *service = bt_bap_get_user_data(bap);
-	struct btd_device *device = btd_service_get_device(service);
+	struct btd_service *service;
+	struct btd_device *device;
 	struct bass_delegator *dg;
 
 	DBG("%p", bap);
 
+	service = bt_bap_get_user_data(bap);
+	if (!service)
+		return;
+
+	device = btd_service_get_device(service);
+
 	dg = queue_remove_if(delegators, delegator_match_device, device);
 	if (!dg)
 		return;
-- 
2.43.0


  parent reply	other threads:[~2025-02-20  8:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20  8:58 [PATCH BlueZ 0/3] bap: Update bt_bap user data handling Iulia Tanasescu
2025-02-20  8:58 ` [PATCH BlueZ 1/3] bap: Do not clear user_data before detaching bt_bap Iulia Tanasescu
2025-02-20 10:11   ` bap: Update bt_bap user data handling bluez.test.bot
2025-02-20  8:58 ` [PATCH BlueZ 2/3] bap: Do not set adapter as bt_bap user_data Iulia Tanasescu
2025-02-20  8:58 ` Iulia Tanasescu [this message]
2025-02-21 16:50 ` [PATCH BlueZ 0/3] bap: Update bt_bap user data handling patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250220085811.5033-4-iulia.tanasescu@nxp.com \
    --to=iulia.tanasescu@nxp.com \
    --cc=andrei.istodorescu@nxp.com \
    --cc=claudia.rosu@nxp.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=mihai-octavian.urzica@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.