From 3b8b972a8151c081905f3c1273e5d6cdd3401354 Mon Sep 17 00:00:00 2001 From: Ganesh Ganapathi Batta Date: Tue, 29 Apr 2014 17:32:14 -0700 Subject: [PATCH] fix random crashes in bd2str caused by exceeding string array remove all casts to avoid sign extension of bd address as this may exceed the size of destination str buffer Change-Id: I27dc7e61b52440c6b284b7e9931e6daa66afbf12 --- btif/src/btif_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c index 96685f292..12aa7a953 100644 --- a/btif/src/btif_util.c +++ b/btif/src/btif_util.c @@ -85,7 +85,7 @@ int str2bd(char *str, bt_bdaddr_t *addr) { int32_t i = 0; for (i = 0; i < 6; i++) { - addr->address[i] = (uint8_t) strtoul(str, (char **)&str, 16); + addr->address[i] = (uint8_t)strtoul(str, &str, 16); str++; } return 0; @@ -95,10 +95,10 @@ char *bd2str(const bt_bdaddr_t *bdaddr, bdstr_t *bdstr) { const uint8_t *addr = bdaddr->address; - snprintf((char*)bdstr, sizeof(*bdstr), "%02x:%02x:%02x:%02x:%02x:%02x", + sprintf(*bdstr, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); - return (char *)bdstr; + return *bdstr; } UINT32 devclass2uint(DEV_CLASS dev_class) -- 2.11.0