diff --git a/src/eir.c b/src/eir.c
index 1f8d229..5162b85 100644
--- a/src/eir.c
+++ b/src/eir.c
#endif
#include <errno.h>
+#include <ctype.h>
#include <stdlib.h>
#include <stdint.h>
#include <glib.h>
}
}
+static char *name2utf8(const uint8_t *name, uint8_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);
+
+ 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] = ' ';
+ }
+
+ /* Remove leading and trailing whitespace characters */
+ g_strstrip(utf8_name);
+
+ return g_strdup(utf8_name);
+}
+
int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
{
uint16_t len = 0;
while (data_len > 0 && data[data_len - 1] == '\0')
data_len--;
- if (!g_utf8_validate((char *) data, data_len, NULL))
- break;
-
g_free(eir->name);
- eir->name = g_strndup((char *) data, data_len);
+ eir->name = name2utf8(data, data_len);
eir->name_complete = eir_data[1] == EIR_NAME_COMPLETE;
break;
diff --git a/src/event.c b/src/event.c
index 881da57..ed1b66f 100644
--- a/src/event.c
+++ b/src/event.c
#define _GNU_SOURCE
#include <stdio.h>
-#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
char filename[PATH_MAX + 1];
char local_addr[18], peer_addr[18];
GKeyFile *key_file;
- char *data, utf8_name[MGMT_MAX_NAME_LENGTH + 1];
gsize length = 0;
-
- if (!g_utf8_validate(name, -1, NULL)) {
- int i;
-
- memset(utf8_name, 0, sizeof(utf8_name));
- strncpy(utf8_name, name, MGMT_MAX_NAME_LENGTH);
-
- /* 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] = ' ';
- }
- /* Remove leading and trailing whitespace characters */
- g_strstrip(utf8_name);
-
- name = utf8_name;
- }
+ char *data;
if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
return;