OSDN Git Service

fix random crashes in bd2str caused by exceeding string array
authorGanesh Ganapathi Batta <ganeshg@broadcom.com>
Wed, 30 Apr 2014 00:32:14 +0000 (17:32 -0700)
committerMatthew Xie <mattx@google.com>
Tue, 6 May 2014 08:14:25 +0000 (01:14 -0700)
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

index 96685f2..12aa7a9 100644 (file)
@@ -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)