From 1c58c18eaaebce43528617fdd439a4ccf56e1496 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 4 Mar 2011 19:34:04 +0100 Subject: [PATCH] Fix str2ba behaviour on malformed bt address str2ba could create bogus bt address from malformed string. Return all zeros bt address on malformed string. --- lib/bluetooth.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/bluetooth.c b/lib/bluetooth.c index f51e310f4..a1b4c13b6 100644 --- a/lib/bluetooth.c +++ b/lib/bluetooth.c @@ -88,18 +88,18 @@ int ba2str(const bdaddr_t *ba, char *str) int str2ba(const char *str, bdaddr_t *ba) { - uint8_t b[6]; - const char *ptr = str; + bdaddr_t b; int i; - for (i = 0; i < 6; i++) { - b[i] = (uint8_t) strtol(ptr, NULL, 16); - if (i != 5 && !(ptr = strchr(ptr, ':'))) - ptr = ":00:00:00:00:00"; - ptr++; + if (bachk(str) < 0) { + memset(ba, 0, sizeof(*ba)); + return -1; } - baswap(ba, (bdaddr_t *) b); + for (i = 0; i < 6; i++, str += 3) + b.b[i] = strtol(str, NULL, 16); + + baswap(ba, &b); return 0; } -- 2.47.3