Skip to contentSkip to conversation

shared/ad: Fix not checking length on ad_replace_name

PATCH Applied Luiz Augusto von Dentz 4 participants 6 messages Mar 16 – Mar 17 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/ad: Fix not checking length on ad_replace_name

From: Luiz Augusto von Dentz <[email protected]>

iov may carry move then HCI_MAX_NAME_LENGTH in which case it is truncated so it doesn't overflow utf8_name.

---
 src/shared/ad.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/shared/ad.c +2 -1
index ac238014bcea..b1d1b84611aa 100644
@@ -278,7 +278,8 @@ static bool ad_replace_name(struct bt_ad *ad, struct iovec *iov)
 	char utf8_name[HCI_MAX_NAME_LENGTH + 2];
 
 	memset(utf8_name, 0, sizeof(utf8_name));
-	strncpy(utf8_name, (const char *)iov->iov_base, iov->iov_len);
+	strncpy(utf8_name, (const char *)iov->iov_base,
+			MIN(iov->iov_len, HCI_MAX_NAME_LENGTH));
 
 	if (strisutf8(utf8_name, iov->iov_len))
 		goto done;
Signature · 1 line
2.53.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1067554

---Test result---

Test Summary:

CheckPatch                    PENDING   0.31 seconds
GitLint                       PENDING   0.40 seconds
BuildEll                      PASS      21.13 seconds
BluezMake                     PASS      649.12 seconds
MakeCheck                     PASS      19.28 seconds
MakeDistcheck                 PASS      246.81 seconds
CheckValgrind                 PASS      292.70 seconds
CheckSmatch                   PASS      355.11 seconds
bluezmakeextell               PASS      182.65 seconds
IncrementalBuild              PENDING   0.38 seconds
ScanBuild                     PASS      1018.38 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

https://github.com/bluez/bluez/pull/1966/checks

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Luiz Augusto von Dentz
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 7 lines · On Mon, 16 Mar 2026 16:43:20 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

iov may carry move then HCI_MAX_NAME_LENGTH in which case it is truncated so it doesn't overflow utf8_name.

---
 src/shared/ad.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Here is the summary with links:
- [BlueZ,v1] shared/ad: Fix not checking length on ad_replace_name

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=11d05ece674f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Luiz Augusto von Dentz
Quoted 19 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

iov may carry move then HCI_MAX_NAME_LENGTH in which case it is truncated so it doesn't overflow utf8_name.
---
 src/shared/ad.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
src/shared/ad.c +0 -0
index ac238014bcea..b1d1b84611aa 100644
@@ -278,7 +278,8 @@ static bool ad_replace_name(struct bt_ad *ad,
 struct iovec *iov)
  	char utf8_name[HCI_MAX_NAME_LENGTH + 2];


  memset(utf8_name, 0, sizeof(utf8_name));

src/shared/ad.c +0 -1
-	strncpy(utf8_name, (const char *)iov->iov_base, iov-
Quoted 1 line

iov_len);

src/shared/ad.c static bool ad_replace_name(struct bt_ad *ad, struct iovec *iov) · line 282

Quoted 2 lines
src/shared/ad.c +2 -0
+	strncpy(utf8_name, (const char *)iov->iov_base,
+			MIN(iov->iov_len, HCI_MAX_NAME_LENGTH));

As I mentioned in my review, utf8_name could also have been shrunk by one byte.

Quoted 3 lines


  if (strisutf8(utf8_name, iov->iov_len))
  goto done;

author maintainer
#4 lore raw

Hi Bastien,

Quoted 18 lines · Bastien Nocera
Quoted 16 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

iov may carry move then HCI_MAX_NAME_LENGTH in which case it is truncated so it doesn't overflow utf8_name.

---
 src/shared/ad.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/shared/ad.c +0 -0
index ac238014bcea..b1d1b84611aa 100644
@@ -278,7 +278,8 @@ static bool ad_replace_name(struct bt_ad *ad,
 struct iovec *iov)
      char utf8_name[HCI_MAX_NAME_LENGTH + 2];
 
Quoted 8 lines

src/shared/ad.c static bool ad_replace_name(struct bt_ad *ad, struct iovec *iov) · line 282

Quoted 5 lines
src/shared/ad.c +2 -1
      memset(utf8_name, 0, sizeof(utf8_name));
-     strncpy(utf8_name, (const char *)iov->iov_base, iov-
 >iov_len);
+     strncpy(utf8_name, (const char *)iov->iov_base,
+                     MIN(iov->iov_len, HCI_MAX_NAME_LENGTH));

As I mentioned in my review, utf8_name could also have been shrunk by one byte.

What review?

Quoted 3 lines
Quoted 3 lines
src/shared/ad.c +0 -0
      if (strisutf8(utf8_name, iov->iov_len))
              goto done;
Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw
Quoted 25 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 21 lines · Bastien Nocera
Quoted 19 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

iov may carry move then HCI_MAX_NAME_LENGTH in which case it is truncated so it doesn't overflow utf8_name.
---
 src/shared/ad.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
src/shared/ad.c +0 -1
index ac238014bcea..b1d1b84611aa 100644
@@ -278,7 +278,8 @@ static bool ad_replace_name(struct bt_ad *ad,
 struct iovec *iov)
       char utf8_name[HCI_MAX_NAME_LENGTH + 2];
 
       memset(utf8_name, 0, sizeof(utf8_name));
-     strncpy(utf8_name, (const char *)iov->iov_base, iov-
 > iov_len);
Quoted 8 lines
Quoted 6 lines

src/shared/ad.c static bool ad_replace_name(struct bt_ad *ad, struct iovec *iov) · line 282

Quoted 2 lines
src/shared/ad.c +2 -0
+     strncpy(utf8_name, (const char *)iov->iov_base,
+                     MIN(iov->iov_len, HCI_MAX_NAME_LENGTH));

As I mentioned in my review, utf8_name could also have been shrunk by
one byte.

What review?

https://lore.kernel.org/linux-bluetooth/[email protected]/

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
src/shared/ad.c +0 -0
       if (strisutf8(utf8_name, iov->iov_len))

              goto done;