Fix static analysis issues in bt-api 54/150154/1
authorAtul Rai <a.rai@samsung.com>
Mon, 11 Sep 2017 08:20:29 +0000 (13:50 +0530)
committerAtul Rai <a.rai@samsung.com>
Thu, 14 Sep 2017 11:43:42 +0000 (17:13 +0530)
Change-Id: I36f4f9ca80d649165cac2661a459fb2fd601672a
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-api/bt-common.c
bt-api/bt-event-handler.c
bt-api/bt-hid-device.c
bt-api/include/bt-common.h
bt-api/include/bt-event-handler.h

index 746ca66..0b5d9d1 100644 (file)
@@ -272,6 +272,7 @@ void _bt_convert_addr_string_to_secure_string(char *addr,
        ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
 
        strncpy(addr, address, len);
+       addr[len] = '\0';
 
        addr[len-1] = 'X';
        addr[len-2] = 'X';
index ffd931a..5b59ec5 100644 (file)
@@ -2833,44 +2833,6 @@ static void __bt_event_data_free(void *data)
        g_free(cb_data);
 }
 
-int _bt_register_event_custom(int event_type, const char *path, const char *interface,
-               GDBusSignalCallback event_func, void *event_cb, void *user_data)
-{
-       GDBusConnection *connection_type;
-       bt_event_info_t *cb_data;
-
-       retv_if(NULL == path, BLUETOOTH_ERROR_INVALID_PARAM);
-       retv_if(NULL == interface, BLUETOOTH_ERROR_INVALID_PARAM);
-       retv_if(NULL == event_func, BLUETOOTH_ERROR_INVALID_PARAM);
-       retv_if(NULL == event_cb, BLUETOOTH_ERROR_INVALID_PARAM);
-
-       if (is_initialized == FALSE)
-               _bt_init_event_handler();
-
-       if (__bt_event_is_registered(event_type) == TRUE) {
-               BT_ERR("The event is already registed");
-               return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
-       }
-
-       connection_type = _bt_gdbus_get_system_gconn();
-       if (connection_type == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
-
-       cb_data = g_new0(bt_event_info_t, 1);
-
-       cb_data->event_type = event_type;
-       cb_data->cb = event_cb;
-       cb_data->user_data = user_data;
-
-       cb_data->id = g_dbus_connection_signal_subscribe(connection_type,
-                               NULL, interface, NULL, path, NULL, 0,
-                               event_func, cb_data, NULL);
-
-       event_list = g_slist_append(event_list, cb_data);
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
 #ifndef GATT_DIRECT
 static void __bt_gatt_server_event_filter(GDBusConnection *connection,
                                                 const gchar *sender_name,
@@ -3036,10 +2998,15 @@ static void __bt_gatt_server_event_filter(GDBusConnection *connection,
 
 int _bt_register_event(int event_type, void *event_cb, void *user_data)
 {
+       GDBusConnection *connection_type;
        GDBusSignalCallback event_func;
+       bt_event_info_t *cb_data;
        const char *path;
        const char *interface = BT_EVENT_SERVICE;
 
+       if (is_initialized == FALSE)
+               _bt_init_event_handler();
+
        if (__bt_event_is_registered(event_type) == TRUE) {
                BT_ERR("The event is already registed");
                return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
@@ -3123,7 +3090,7 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data)
                break;
 #endif
        case BT_HDP_EVENT:
-               BT_DBG("BT_HID_DEVICE_EVENT");
+               BT_DBG("BT_HDP_EVENT");
                event_func = __bt_hdp_event_filter;
                path = BT_HDP_DEVICE_PATH;
                break;
@@ -3138,8 +3105,23 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       return _bt_register_event_custom(event_type, path,
-                       interface, event_func, event_cb, user_data);
+       connection_type = _bt_gdbus_get_system_gconn();
+       if (connection_type == NULL)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       cb_data = g_new0(bt_event_info_t, 1);
+
+       cb_data->event_type = event_type;
+       cb_data->cb = event_cb;
+       cb_data->user_data = user_data;
+
+       cb_data->id = g_dbus_connection_signal_subscribe(connection_type,
+                               NULL, interface, NULL, path, NULL, 0,
+                               event_func, cb_data, NULL);
+
+       event_list = g_slist_append(event_list, cb_data);
+
+       return BLUETOOTH_ERROR_NONE;
 }
 
 int _bt_unregister_event(int event_type)
index d02a9b8..d6b307f 100755 (executable)
@@ -325,7 +325,7 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond,
 {
        hid_connected_device_info_t *info = user_data;
        GIOStatus status = G_IO_STATUS_NORMAL;
-       char buffer[20];
+       char buffer[BT_RFCOMM_BUFFER_LEN];
        gsize len = 0;
        GError *err = NULL;
        guint8  header, type, param;
@@ -679,7 +679,7 @@ BT_EXPORT_API int bluetooth_hid_device_connect(const char *remote_addr)
                return BLUETOOTH_ERROR_PERMISSION_DEINED;
        }
 
-       memcpy(device_address, remote_addr, BT_ADDRESS_STRING_SIZE);
+       g_strlcpy(device_address, remote_addr, BT_ADDRESS_STRING_SIZE);
        ret = _bt_connect_profile(device_address, HID_DEVICE_UUID,
                                __hid_connect_response_cb, NULL);
 
index 0b99e4e..4851687 100755 (executable)
@@ -211,8 +211,11 @@ extern "C" {
 
 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
 
-
+#ifndef GATT_DIRECT
+#define BT_MAX_USER_INFO 6
+#else
 #define BT_MAX_USER_INFO 5
+#endif
 #define RFKILL_EVENT_SIZE 8
 #define RFKILL_NODE "/dev/rfkill"
 
@@ -385,6 +388,8 @@ void _bluetooth_hid_free_hid_info(void);
 void _bt_hdp_app_remove_obj_info(unsigned int channe_id);
 int _bt_hdp_app_acquire_fd(bt_hdp_connected_t *conn_info);
 
+bluetooth_device_info_t *_bt_get_device_info_in_message(GVariant *parameters, int *ret);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index c53b176..72c178f 100755 (executable)
@@ -42,9 +42,6 @@ int _bt_init_event_handler(void);
 
 int _bt_deinit_event_handler(void);
 
-int _bt_register_event_custom(int event_type, const char *path, const char *interface,
-               GDBusSignalCallback event_func, void *event_cb, void *user_data);
-
 int _bt_register_event(int event_type, void *event_cb, void *user_data);
 
 int _bt_unregister_event(int event_type);
@@ -71,8 +68,6 @@ int _bt_hid_device_get_fd(const char *address, int *ctrl, int *intr);
 
 int new_hid_connection(const char *path, int fd, bluetooth_device_address_t *addr);
 
-bluetooth_device_info_t *_bt_get_device_info_in_message(GVariant *parameters, int *ret);
-
 #ifdef __cplusplus
 }
 #endif