public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v3 4/7] audio/gap: Use strtoutf8 for GAP device name
Date: Tue,  8 Jul 2025 17:43:04 +0200	[thread overview]
Message-ID: <20250708154308.238963-5-frederic.danis@collabora.com> (raw)
In-Reply-To: <20250708154308.238963-1-frederic.danis@collabora.com>

Truncate the string to first character before invalid UTF-8 one
instead of replacing non ascii characters by spaces.
---
 profiles/gap/gas.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 08aaf19cb..74dabf41f 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -69,21 +69,12 @@ static void gas_free(struct gas *gas)
 static char *name2utf8(const uint8_t *name, uint16_t len)
 {
 	char utf8_name[HCI_MAX_NAME_LENGTH + 2];
-	int i;
-
-	if (g_utf8_validate((const char *) name, len, NULL))
-		return g_strndup((char *) name, len);
 
 	len = MIN(len, sizeof(utf8_name) - 1);
 
 	memset(utf8_name, 0, sizeof(utf8_name));
 	strncpy(utf8_name, (char *) name, len);
-
-	/* Assume ASCII, and replace all non-ASCII with spaces */
-	for (i = 0; utf8_name[i] != '\0'; i++) {
-		if (!isascii(utf8_name[i]))
-			utf8_name[i] = ' ';
-	}
+	strtoutf8(utf8_name, len);
 
 	/* Remove leading and trailing whitespace characters */
 	g_strstrip(utf8_name);
-- 
2.43.0


  parent reply	other threads:[~2025-07-08 15:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-08 15:43 [PATCH BlueZ v3 0/7] audio/avrcp: Fix crash with invalid UTF-8 item name Frédéric Danis
2025-07-08 15:43 ` [PATCH BlueZ v3 1/7] shared/util: Add strtoutf8 function Frédéric Danis
2025-07-08 17:06   ` audio/avrcp: Fix crash with invalid UTF-8 item name bluez.test.bot
2025-07-08 15:43 ` [PATCH BlueZ v3 2/7] " Frédéric Danis
2025-07-08 15:43 ` [PATCH BlueZ v3 3/7] audio/mcp: Use strtoutf8 for player name and track title Frédéric Danis
2025-07-08 15:43 ` Frédéric Danis [this message]
2025-07-08 15:43 ` [PATCH BlueZ v3 5/7] eir: Use strtoutf8 for device names Frédéric Danis
2025-07-08 15:43 ` [PATCH BlueZ v3 6/7] shared/ad: Use strtoutf8 for name Frédéric Danis
2025-07-08 17:12   ` Pauli Virtanen
2025-07-08 17:16     ` Pauli Virtanen
2025-07-08 17:19     ` Luiz Augusto von Dentz
2025-07-08 15:43 ` [PATCH BlueZ v3 7/7] unit/test-eir: Add name encoding tests Frédéric Danis
2025-07-08 16:30 ` [PATCH BlueZ v3 0/7] audio/avrcp: Fix crash with invalid UTF-8 item name patchwork-bot+bluetooth

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=20250708154308.238963-5-frederic.danis@collabora.com \
    --to=frederic.danis@collabora.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