public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Ismagil Iskakov <i.iskakov@omp.ru>
To: <linux-bluetooth@vger.kernel.org>
Cc: Ismagil Iskakov <i.iskakov@omp.ru>
Subject: [PATCH BlueZ 08/11] src/shared: move null checks before dereferencing
Date: Tue, 8 Jul 2025 10:33:31 +0300	[thread overview]
Message-ID: <20250708073334.2393559-9-i.iskakov@omp.ru> (raw)
In-Reply-To: <20250708073334.2393559-1-i.iskakov@omp.ru>

---
 src/shared/bap.c     | 14 ++++++++------
 src/shared/gatt-db.c |  5 ++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 96fca595b..5b904af9b 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2570,12 +2570,12 @@ static uint8_t bap_ucast_io_dir(struct bt_bap_stream *stream)
 
 static uint8_t bap_bcast_io_dir(struct bt_bap_stream *stream)
 {
-	uint8_t dir;
-	uint8_t pac_type = bt_bap_pac_get_type(stream->lpac);
-
 	if (!stream)
 		return 0x00;
 
+	uint8_t dir;
+	uint8_t pac_type = bt_bap_pac_get_type(stream->lpac);
+
 	if (pac_type == BT_BAP_BCAST_SINK)
 		dir = BT_BAP_BCAST_SOURCE;
 	else
@@ -6144,7 +6144,7 @@ static struct bt_bap_stream *bap_bcast_stream_new(struct bt_bap *bap,
 	struct bt_bap_endpoint *ep = NULL;
 	struct match_pac match;
 
-	if (!bap)
+	if (!bap || !lpac)
 		return NULL;
 
 	if (lpac->type == BT_BAP_BCAST_SOURCE) {
@@ -6153,7 +6153,7 @@ static struct bt_bap_stream *bap_bcast_stream_new(struct bt_bap *bap,
 		memset(&match.codec, 0, sizeof(match.codec));
 
 		bt_bap_foreach_pac(bap, BT_BAP_BCAST_SINK, match_pac, &match);
-		if ((!match.lpac) || (!lpac))
+		if (!match.lpac)
 			return NULL;
 
 		lpac = match.lpac;
@@ -6406,11 +6406,13 @@ unsigned int bt_bap_stream_release(struct bt_bap_stream *stream,
 					void *user_data)
 {
 	unsigned int id;
-	struct bt_bap *bap = stream->bap;
+	struct bt_bap *bap;
 
 	if (!stream || !stream->ops || !stream->ops->release)
 		return 0;
 
+	bap = stream->bap;
+
 	if (!bt_bap_ref_safe(bap))
 		return 0;
 
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 8951079be..a4fa8aed9 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1391,12 +1391,15 @@ static void find_by_type(struct gatt_db_attribute *attribute, void *user_data)
 {
 	struct find_by_type_value_data *search_data = user_data;
 
+	if (!attribute)
+		return;
+
 	/* TODO: fix for read-callback based attributes */
 	if (search_data->value) {
 		if (search_data->value_len != attribute->value_len)
 			return;
 
-		if (!attribute || !attribute->value)
+		if (!attribute->value)
 			return;
 
 		if (memcmp(attribute->value, search_data->value,
-- 
2.34.1


  parent reply	other threads:[~2025-07-08  7:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-08  7:33 [PATCH BlueZ 00/11] Fix bugs found by static analysis Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 01/11] btio: fix range validation of security level Ismagil Iskakov
2025-07-08  7:51   ` Fix bugs found by static analysis bluez.test.bot
2025-07-08  7:33 ` [PATCH BlueZ 02/11] profiles/audio: add nullity checks Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 03/11] src/shared: " Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 04/11] isotest: close fd after sending when nconn=1 Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 05/11] obexd/client: fix err condition causing memleak Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 06/11] profiles/audio: fix memleak of bt_bap Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 07/11] src/shared: fix memleak Ismagil Iskakov
2025-07-08  7:33 ` Ismagil Iskakov [this message]
2025-07-08  7:33 ` [PATCH BlueZ 09/11] isotest: remove repeating conditions Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 10/11] profiles/audio: fix io_unlink args order Ismagil Iskakov
2025-07-08  7:33 ` [PATCH BlueZ 11/11] src/plugin: fix " Ismagil Iskakov

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=20250708073334.2393559-9-i.iskakov@omp.ru \
    --to=i.iskakov@omp.ru \
    --cc=linux-bluetooth@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox