From 60de2f6009642c032ad751339f2ad9cfd5c1025d Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 8 Nov 2010 16:43:42 +0000 Subject: [PATCH] Handle non-UTF-8 device names http://thread.gmane.org/gmane.linux.bluez.kernel/1687 https://bugzilla.redhat.com/show_bug.cgi?id=450081 --- src/event.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/event.c b/src/event.c index d5bf96714..cf68711b9 100644 --- a/src/event.c +++ b/src/event.c @@ -28,6 +28,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -562,12 +563,18 @@ void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, struct remote_dev_info match, *dev_info; if (status == 0) { - char *end; - - /* It's ok to cast end between const and non-const since - * we know it points to inside of name which is non-const */ - if (!g_utf8_validate(name, -1, (const char **) &end)) - *end = '\0'; + if (!g_utf8_validate(name, -1, NULL)) { + int i; + + /* Assume ASCII, and replace all non-ASCII with + * spaces */ + for (i = 0; name[i] != '\0'; i++) { + if (!isascii(name[i])) + name[i] = ' '; + } + /* Remove leading and trailing whitespace characters */ + g_strstrip(name); + } write_device_name(local, peer, name); } -- 2.47.3