Fixed paired device config UUID parsing logic

Also added unit tests to cover this bug.

Bug: 26883553
Change-Id: Ice8641fad5c38ee43f1b080665dde70979f9d60f
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 6da4514..917508c 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -187,38 +187,6 @@
 **  Static functions
 ************************************************************************************/
 
-/*******************************************************************************
-**
-** Function         btif_in_split_uuids_string_to_list
-**
-** Description      Internal helper function to split the string of UUIDs
-**                  read from the NVRAM to an array
-**
-** Returns          None
-**
-*******************************************************************************/
-static void btif_in_split_uuids_string_to_list(char *str, bt_uuid_t *p_uuid,
-                                               uint32_t *p_num_uuid)
-{
-    char buf[64];
-    char *p_start = str;
-    char *p_needle;
-    uint32_t num = 0;
-    do
-    {
-        //p_needle = strchr(p_start, ';');
-        p_needle = strchr(p_start, ' ');
-        if (p_needle < p_start) break;
-        memset(buf, 0, sizeof(buf));
-        strncpy(buf, p_start, (p_needle-p_start));
-        string_to_uuid(buf, p_uuid + num);
-        num++;
-        p_start = ++p_needle;
-
-    } while (*p_start != 0);
-    *p_num_uuid = num;
-}
-
 static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
 {
     bdstr_t bdstr = {0};
@@ -389,8 +357,7 @@
                                     BTIF_STORAGE_PATH_REMOTE_SERVICE, value, &size))
             {
                 bt_uuid_t *p_uuid = (bt_uuid_t*)prop->val;
-                uint32_t num_uuids = 0;
-                btif_in_split_uuids_string_to_list(value, p_uuid, &num_uuids);
+                size_t num_uuids = btif_split_uuids_string(value, p_uuid, BT_MAX_NUM_UUIDS);
                 prop->len = num_uuids * sizeof(bt_uuid_t);
                 ret = TRUE;
             }
@@ -594,6 +561,34 @@
 
 /*******************************************************************************
 **
+** Function         btif_split_uuids_string
+**
+** Description      Internal helper function to split the string of UUIDs
+**                  read from the NVRAM to an array
+**
+** Returns          Number of UUIDs parsed from the supplied string
+**
+*******************************************************************************/
+size_t btif_split_uuids_string(const char *str, bt_uuid_t *p_uuid, size_t max_uuids)
+{
+    assert(str);
+    assert(p_uuid);
+
+    size_t num_uuids = 0;
+    while (str && num_uuids < max_uuids)
+    {
+        bool rc = string_to_uuid(str, p_uuid++);
+        if (!rc) break;
+        num_uuids++;
+        str = strchr(str, ' ');
+        if (str) str++;
+    }
+
+    return num_uuids;
+}
+
+/*******************************************************************************
+**
 ** Function         btif_storage_get_adapter_property
 **
 ** Description      BTIF storage API - Fetches the adapter property->type
diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c
index 27d68c2..f4cffcb 100644
--- a/btif/src/btif_util.c
+++ b/btif/src/btif_util.c
@@ -30,6 +30,7 @@
 
 #include "btif_util.h"
 
+#include <assert.h>
 #include <ctype.h>
 #include <netinet/in.h>
 #include <stdio.h>
@@ -111,13 +112,19 @@
     memcpy(uuid128->uu + 2, &uuid16_bo, sizeof(uint16_t));
 }
 
-void string_to_uuid(const char *str, bt_uuid_t *p_uuid)
+bool string_to_uuid(const char *str, bt_uuid_t *p_uuid)
 {
+    assert(p_uuid);
+    if (str == NULL)
+        return false;
+
     uint32_t uuid0, uuid4;
     uint16_t uuid1, uuid2, uuid3, uuid5;
 
-    sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
+    int rc = sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
                 &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
+    if (rc != 6)
+        return false;
 
     uuid0 = htonl(uuid0);
     uuid1 = htons(uuid1);
@@ -133,8 +140,7 @@
     memcpy(&(p_uuid->uu[10]), &uuid4, 4);
     memcpy(&(p_uuid->uu[14]), &uuid5, 2);
 
-    return;
-
+    return true;
 }
 
 void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str)