Linux bluetooth development
 help / color / mirror / Atom feed
From: Roland Schober <rolandschober1968@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, Roland Schober <rolandschober1968@gmail.com>
Subject: [RFC PATCH BlueZ v2 4/9] client/mgmt: Fix length of byte arrays with empty entries
Date: Wed,  2 Dec 2026 13:52:36 +0100	[thread overview]
Message-ID: <20261202125241.348452-5-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261202125241.348452-1-rolandschober1968@gmail.com>

str2bytearray() counts the empty entries which two separators in a row
or one at the end of the argument leave, although it stores nothing for
them. The length it returns is then larger than the number of octets
given, and with enough empty entries larger than the buffer: hci-cmd
sends octets it was not given, and octets beyond its packet.

Count the octets which are stored.

Fixes: 95e89cd2e4f8 ("client/mgmt: Add hci-cmd command")
Assisted-by: Claude:claude-fable-5-2
---
 client/mgmt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/client/mgmt.c b/client/mgmt.c
index a7069e5bb..bdf1bbfec 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c
@@ -2398,9 +2398,9 @@ static void cmd_set_flags(int argc, char **argv)
 static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len)
 {
 	char *entry;
-	long i;
+	long i = 0;
 
-	for (i = 0; (entry = strsep(&arg, " \t")) != NULL; i++) {
+	while ((entry = strsep(&arg, " \t")) != NULL) {
 		long v;
 		char *endptr = NULL;
 
@@ -2418,7 +2418,7 @@ static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len)
 			return NULL;
 		}
 
-		val[i] = v;
+		val[i++] = v;
 	}
 
 	*val_len = i;
-- 
2.47.3


  parent reply	other threads:[~2026-12-02 12:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:52 [RFC PATCH BlueZ v2 0/9] Periodic advertising and PAwR over MGMT Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 1/9] doc/mgmt: Add PA and PAwR commands and events Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 2/9] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 3/9] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
2026-12-02 12:52 ` Roland Schober [this message]
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 5/9] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 6/9] monitor: Add PAwR HCI definitions Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 7/9] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 8/9] emulator/btdev: Add PAwR advertiser Roland Schober
2026-12-02 12:52 ` [RFC PATCH BlueZ v2 9/9] mgmt-tester: Add periodic advertising and PAwR tests Roland Schober

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=20261202125241.348452-5-rolandschober1968@gmail.com \
    --to=rolandschober1968@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox