Linux bluetooth development
 help / color / mirror / Atom feed
From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Roland Schober <rolandschober1968@gmail.com>
Subject: [PATCH BlueZ 5/5] monitor: Fix decoding of Public Broadcast Announcements
Date: Fri, 20 Nov 2026 23:26:24 +0100	[thread overview]
Message-ID: <20261120222624.150321-6-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261120222624.150321-1-rolandschober1968@gmail.com>

print_pbp_announcement() takes the result of util_iov_pull_u8() the
wrong way round: a well formed announcement is reported as "invalid
features", and an empty one is decoded from uninitialised variables,
which can hand a NULL pointer to bt_bap_debug_metadata().

Check the metadata length against the remaining data as well.

Fixes: 3171f7fd3685 ("monitor: Add decoding support for Public Broadcast Announcements")
Assisted-by: Claude:claude-fable-5-2
---
 monitor/packet.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index 042a2ecb6..7fdab7cc5 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -4101,7 +4101,7 @@ static void print_pbp_announcement(const uint8_t *data, uint8_t data_len)
 	iov.iov_base = (void *) data;
 	iov.iov_len = data_len;
 
-	if (util_iov_pull_u8(&iov, &feat)) {
+	if (!util_iov_pull_u8(&iov, &feat)) {
 		print_text(COLOR_ERROR, "  invalid features");
 		return;
 	}
@@ -4113,7 +4113,7 @@ static void print_pbp_announcement(const uint8_t *data, uint8_t data_len)
 		print_text(COLOR_UNKNOWN_SERVICE_CLASS,
 					"  Unknown feature (0x%2.2x)", mask);
 
-	if (util_iov_pull_u8(&iov, &len)) {
+	if (!util_iov_pull_u8(&iov, &len)) {
 		print_text(COLOR_ERROR, "  invalid metadata length");
 		return;
 	}
@@ -4122,6 +4122,11 @@ static void print_pbp_announcement(const uint8_t *data, uint8_t data_len)
 		return;
 
 	meta.iov_base = util_iov_pull_mem(&iov, len);
+	if (!meta.iov_base) {
+		print_text(COLOR_ERROR, "  invalid metadata");
+		return;
+	}
+
 	meta.iov_len = len;
 
 	bt_bap_debug_metadata(meta.iov_base, meta.iov_len, print_ltv,
-- 
2.47.3


      parent reply	other threads:[~2026-11-20 22:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 22:26 [PATCH BlueZ 0/5] monitor: Fix reads beyond advertising data Roland Schober
2026-11-20 22:26 ` [PATCH BlueZ 1/5] monitor: Fix overflow of the name buffer in print_eir Roland Schober
2026-11-20 22:26 ` [PATCH BlueZ 2/5] monitor: Fix reading Flags beyond empty AD structures Roland Schober
2026-11-20 22:26 ` [PATCH BlueZ 3/5] monitor: Fix reading beyond a short Mesh Beacon Roland Schober
2026-11-20 22:26 ` [PATCH BlueZ 4/5] monitor: Fix reading beyond the Apple manufacturer data Roland Schober
2026-11-20 22:26 ` Roland Schober [this message]

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=20261120222624.150321-6-rolandschober1968@gmail.com \
    --to=rolandschober1968@gmail.com \
    --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