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 v3 05/12] client/mgmt: Refuse negative values in byte arrays
Date: Thu,  3 Dec 2026 23:15:25 +0100	[thread overview]
Message-ID: <20261203221532.682750-6-rolandschober1968@gmail.com> (raw)
In-Reply-To: <20261203221532.682750-1-rolandschober1968@gmail.com>

str2bytearray() checks the upper limit of an octet only, so a negative
value is stored as its low eight bits: hci-cmd sends 0xff for -1 and
0x00 for -256, without an error.

Refuse values below 0 like those above 255.

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

diff --git a/client/mgmt.c b/client/mgmt.c
index bdf1bbfec..fa5abec9e 100644
--- a/client/mgmt.c
+++ b/client/mgmt.c
@@ -2413,7 +2413,8 @@ static uint8_t *str2bytearray(char *arg, uint8_t *val, long *val_len)
 		}
 
 		v = strtol(entry, &endptr, 0);
-		if (!endptr || *endptr != '\0' || v > UINT8_MAX) {
+		if (!endptr || *endptr != '\0' || v < 0 ||
+							v > UINT8_MAX) {
 			bt_shell_printf("Invalid value at index %ld\n", i);
 			return NULL;
 		}
-- 
2.47.3


  parent reply	other threads:[~2026-12-03 22:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 22:15 [RFC PATCH BlueZ v3 00/12] Periodic advertising and PAwR over MGMT Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 01/12] doc/mgmt: Add PA and PAwR commands and events Roland Schober
2026-12-04  8:23   ` Periodic advertising and PAwR over MGMT bluez.test.bot
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 02/12] lib/mgmt: Add periodic advertising and PAwR definitions Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 03/12] monitor: Decode PA and PAwR MGMT commands and events Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 04/12] client/mgmt: Fix length of byte arrays with empty entries Roland Schober
2026-12-03 22:15 ` Roland Schober [this message]
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 06/12] client/mgmt: Add pa-params, pa-data and pawr-serve commands Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 07/12] monitor: Add PAwR HCI definitions Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 08/12] emulator/btdev: Check the length of PA commands Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 09/12] emulator/btdev: Keep the advertising set after a timeout Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 10/12] emulator/btdev: Keep advertising sets with PA enabled Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 11/12] emulator/btdev: Add PAwR advertiser Roland Schober
2026-12-03 22:15 ` [RFC PATCH BlueZ v3 12/12] 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=20261203221532.682750-6-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