All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabian Greffrath <fabian@greffrath.com>
To: linux-bluetooth@vger.kernel.org
Subject: Re: Detect invalid (i.e. non-UTF-8) device names and fix them during initialization phase
Date: Wed, 05 May 2010 12:27:37 +0200	[thread overview]
Message-ID: <4BE14819.4080903@greffrath.com> (raw)
In-Reply-To: <4BE14458.1020908@greffrath.com>

[-- Attachment #1: Type: text/plain, Size: 356 bytes --]

Dear Bluez list,

I am sorry, I know this is the worst way to start getting in touch 
with a software project, but I accidently attached the wrong patch to 
my previous email. It's configure_device() that must be patched. 
Please find a corrected patch attached (it has been written against 
bluez 4.63 but applies perfectly against 4.64).

Cheers,
Fabian

[-- Attachment #2: fix_invalid_non-utf-8_device_name.patch --]
[-- Type: text/x-diff, Size: 1106 bytes --]

--- bluez-4.63.orig/plugins/hciops.c
+++ bluez-4.63/plugins/hciops.c
@@ -81,6 +81,7 @@ static void configure_device(int index)
 	struct hci_dev_info di;
 	uint16_t policy;
 	int dd, err;
+	char name[249];
 
 	if (hci_devinfo(index, &di) < 0)
 		return;
@@ -96,6 +97,30 @@ static void configure_device(int index)
 		return;
 	}
 
+	if (hci_read_local_name(dd, sizeof(name), name, 1000) < 0) {
+		error("Can't read local name on hci%d: %s (%d)\n",
+						index, strerror(errno), errno);
+		return;
+	}
+
+	name[248] = '\0';
+
+	if (!g_utf8_validate(name, -1, NULL)) {
+		char *utf8_name;
+
+		utf8_name = g_convert(name, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+		if (utf8_name) {
+			debug("Fix invalid non-UTF-8 device name \"%s\" on hci%d to \"%s\"",
+							name, index, utf8_name);
+			if (hci_write_local_name(dd, utf8_name, 2000) < 0) {
+				error("Can't change local name on hci%d: %s (%d)\n",
+								index, strerror(errno), errno);
+				return;
+			}
+			g_free(utf8_name);
+		}
+	}
+
 	/* Set page timeout */
 	if ((main_opts.flags & (1 << HCID_SET_PAGETO))) {
 		write_page_timeout_cp cp;

  reply	other threads:[~2010-05-05 10:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-05 10:11 Detect invalid (i.e. non-UTF-8) device names and fix them during initialization phase Fabian Greffrath
2010-05-05 10:27 ` Fabian Greffrath [this message]
2010-05-05 15:02   ` Stefan Seyfried
2010-05-05 15:14     ` Fabian Greffrath
2010-05-06 14:42     ` Fabian Greffrath
2010-05-06 15:03       ` Johan Hedberg
2010-05-17  8:39         ` [PATCH] Instantly fix non-UTF-8 local device names during device configuration phase Fabian Greffrath

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=4BE14819.4080903@greffrath.com \
    --to=fabian@greffrath.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.