Fix ASAN build error 49/233049/3
authorDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 11 May 2020 23:00:22 +0000 (08:00 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 11 May 2020 23:58:38 +0000 (08:58 +0900)
This patchset resolves 'stringop-overflow' and
'maybe-uninitialized' build error for ASAN

Change-Id: I8fafd8dec17e9df1eae7c220f8984754e20327a2
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-oal/bluez_hal/inc/bt-hal-utils.h
bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-utils.c

index 6fc235a..641c044 100644 (file)
@@ -26,6 +26,7 @@
 #define HAL_UUID_LEN           16
 #define MAX_ADDR_STR_LEN       18
 #define MAX_MANUFACTURE_LEN    240
+#define MAX_STR_BUF_LEN                4096
 
 #define BT_HAL_UUID_16     2
 #define BT_HAL_UUID_32     4
index 4638c92..b24f7d9 100644 (file)
@@ -1189,8 +1189,8 @@ done:
 int _bt_hal_dbus_get_scan_mode(void)
 {
        GDBusProxy *proxy;
-       gboolean discoverable;
-       gboolean connectable;
+       gboolean discoverable = FALSE;
+       gboolean connectable = FALSE;
        GVariant *result;
        GVariant *temp;
        GError *error = NULL;
index d0b0fc2..9a4753f 100644 (file)
@@ -519,16 +519,16 @@ static void bonded_devices2string(char *str, void *prop, int prop_len)
        int count = prop_len / sizeof(bt_bdaddr_t);
        bt_bdaddr_t *addr = prop;
 
-       strncat(str, "{", strlen("{"));
+       strncat(str, "{", MAX_STR_BUF_LEN - strlen(str) - 1);
 
        while (count--) {
                strncat(str, bdaddr2str(addr), MAX_ADDR_STR_LEN);
                if (count)
-                       strncat(str, ", ", strlen(", "));
+                       strncat(str, ", ", MAX_STR_BUF_LEN - strlen(str) - 1);
                addr++;
        }
 
-       strncat(str, "}", strlen("}"));
+       strncat(str, "}", MAX_STR_BUF_LEN - strlen(str) - 1);
 }
 
 static void uuids2string(char *str, void *prop, int prop_len)
@@ -536,16 +536,16 @@ static void uuids2string(char *str, void *prop, int prop_len)
        int count = prop_len / sizeof(bt_uuid_t);
        bt_uuid_t *uuid = prop;
 
-       strncat(str, "{",  strlen("{"));
+       strncat(str, "{",  MAX_STR_BUF_LEN - strlen(str) - 1);
 
        while (count--) {
                strncat(str, btuuid2str(uuid->uu), MAX_UUID_STR_LEN);
                if (count)
-                       strncat(str, ", ",  strlen(", "));
+                       strncat(str, ", ",  MAX_STR_BUF_LEN - strlen(str) - 1);
                uuid++;
        }
 
-       strncat(str, "}", strlen("}"));
+       strncat(str, "}", MAX_STR_BUF_LEN - strlen(str) - 1);
 }
 
 const char* bt_property_type_t2str(bt_property_type_t prop_type)
@@ -722,12 +722,12 @@ static void local_le_feat2string(char *str, const bt_local_le_features_t *f, int
 const char *btproperty2str(const bt_property_t *property)
 {
        bt_service_record_t *rec;
-       static char buf[4096];
-       int buf_len = 4096;
+       static char buf[MAX_STR_BUF_LEN];
+       int buf_len = MAX_STR_BUF_LEN;
        int ret;
        char *p;
 
-       memset(buf, 0x00, 4096);
+       memset(buf, 0x00, MAX_STR_BUF_LEN);
        ret = snprintf(buf, buf_len, "type=%s len=%d val=",
                        bt_property_type_t2str(property->type),
                        property->len);