Check null handle for network info 60/215660/2 submit/tizen/20191014.135954
authorhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 14 Oct 2019 05:07:16 +0000 (14:07 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 14 Oct 2019 07:28:22 +0000 (16:28 +0900)
Change-Id: I4f593a168b8f948cafe86fa1fbe8f3ac5df9b9ac
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
packaging/libnet-client.spec
src/network-cm-intf.c
src/network-dbus-request.c
src/network-internal.c
src/network-signal-handler.c

index 6ff35df..9b566db 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          libnet-client
 Summary:       Network Client library (Shared library)
-Version:       1.1.72
+Version:       1.1.73
 Release:       1
 Group:         System/Network
 License:       Flora-1.1
index 73e24b5..310e023 100755 (executable)
@@ -417,7 +417,8 @@ static void __net_abort_open_connection(network_info_t *network_info, const char
        event_data->Data = NULL;
 
        NETWORK_LOG(NETWORK_LOW, "%s, Error: %d", event_string, event_data->Error);
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
        __NETWORK_FUNC_EXIT__;
@@ -493,14 +494,16 @@ EXPORT_API void net_deregister_client(void *handle)
 
        network_info_t *network_info = (network_info_t *)handle;
 
-       network_info->event_callback = NULL;
-       network_info->user_data = NULL;
+       if (network_info) {
+               network_info->event_callback = NULL;
+               network_info->user_data = NULL;
 
-       _net_deregister_signal(network_info);
-       _net_dbus_close_gdbus_call(network_info);
-       _net_clear_request_table();
+               _net_deregister_signal(network_info);
+               _net_dbus_close_gdbus_call(network_info);
+               _net_clear_request_table();
 
-       g_free(network_info);
+               g_free(network_info);
+       }
 
        __NETWORK_FUNC_EXIT__;
 }
index 9b69a80..66f3119 100755 (executable)
@@ -190,7 +190,8 @@ static void __net_open_connection_reply(GObject *source_object, GAsyncResult *re
                return;
        }
 
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
 done:
@@ -252,7 +253,8 @@ static void __net_close_connection_reply(GObject *source_object, GAsyncResult *r
                return;
        }
 
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
 done:
@@ -312,7 +314,8 @@ static void __net_reset_cellular_reply(GObject *source_object, GAsyncResult *res
                return;
        }
 
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
        __NETWORK_FUNC_EXIT__;
@@ -370,7 +373,8 @@ static void __net_set_default_reply(GObject *source_object, GAsyncResult *res, g
                return;
        }
 
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
        __NETWORK_FUNC_EXIT__;
index ad33756..cee1efa 100755 (executable)
@@ -267,29 +267,33 @@ int _net_dbus_create_gdbus_call(network_info_t *network_info)
        g_type_init();
 #endif
 
-       network_info->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (network_info->connection == NULL) {
-               /* LCOV_EXCL_START */
-               if (error != NULL) {
-                       NETWORK_LOG(NETWORK_ERROR,
-                                       "Failed to connect to the D-BUS daemon [%s]", error->message);
-                       g_error_free(error);
+       if (network_info) {
+               network_info->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (network_info->connection == NULL) {
+                       /* LCOV_EXCL_START */
+                       if (error != NULL) {
+                               NETWORK_LOG(NETWORK_ERROR,
+                                               "Failed to connect to the D-BUS daemon [%s]", error->message);
+                               g_error_free(error);
+                       }
+                       /* LCOV_EXCL_STOP */
+                       return NET_ERR_UNKNOWN;
                }
-               /* LCOV_EXCL_STOP */
-               return NET_ERR_UNKNOWN;
-       }
 
-       network_info->cancellable = g_cancellable_new();
+               network_info->cancellable = g_cancellable_new();
+       }
 
        return NET_ERR_NONE;
 }
 
 void _net_dbus_close_gdbus_call(network_info_t *network_info)
 {
-       g_cancellable_cancel(network_info->cancellable);
-       g_object_unref(network_info->cancellable);
-       network_info->cancellable = NULL;
+       if (network_info) {
+               g_cancellable_cancel(network_info->cancellable);
+               g_object_unref(network_info->cancellable);
+               network_info->cancellable = NULL;
 
-       g_object_unref(network_info->connection);
-       network_info->connection = NULL;
+               g_object_unref(network_info->connection);
+               network_info->connection = NULL;
+       }
 }
index 931129d..b3e12e9 100755 (executable)
@@ -82,7 +82,8 @@ static int __net_handle_wifi_power_rsp(gboolean value, network_info_t *network_i
        event_data->Datalength = sizeof(net_wifi_state_t);
        event_data->Data = &(net_wifi_state);
 
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
        __NETWORK_FUNC_EXIT__;
@@ -96,6 +97,12 @@ static void __net_handle_state_ind(network_info_t *network_info,
 
        net_event_info_t *event_data = NULL;
 
+       if (network_info == NULL ||
+               network_info->event_callback == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return;
+       }
+
        event_data = g_try_new0(net_event_info_t, 1);
        if (event_data == NULL) {
                __NETWORK_FUNC_EXIT__;
@@ -127,6 +134,12 @@ static void __net_handle_internet_state_ind(network_info_t *network_info,
 
        net_event_info_t *event_data = NULL;
 
+       if (network_info == NULL ||
+               network_info->event_callback == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return;
+       }
+
        event_data = g_try_new0(net_event_info_t, 1);
        if (event_data == NULL) {
                __NETWORK_FUNC_EXIT__;
@@ -215,7 +228,8 @@ static void __net_handle_failure_ind(network_info_t *network_info,
 
        NETWORK_LOG(NETWORK_ERROR, "State failure %d", event_data->Error);
 
-       network_info->event_callback(event_data, network_info->user_data);
+       if (network_info && network_info->event_callback)
+               network_info->event_callback(event_data, network_info->user_data);
        g_free(event_data);
 
        /* Reseting the state back in case of failure state */
@@ -344,7 +358,8 @@ static int __net_handle_service_state_changed(network_info_t *network_info,
                        event_data->Error = Error;
                        g_strlcpy(event_data->ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
 
-                       network_info->event_callback(event_data, network_info->user_data);
+                       if (network_info && network_info->event_callback)
+                               network_info->event_callback(event_data, network_info->user_data);
                        g_free(event_data);
                }
 
@@ -374,7 +389,8 @@ static int __net_handle_service_state_changed(network_info_t *network_info,
 
                        NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
 
-                       network_info->event_callback(event_data, network_info->user_data);
+                       if (network_info && network_info->event_callback)
+                               network_info->event_callback(event_data, network_info->user_data);
                        g_free(event_data);
                        break;
                }
@@ -394,7 +410,8 @@ static int __net_handle_service_state_changed(network_info_t *network_info,
 
                        NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
 
-                       network_info->event_callback(event_data, network_info->user_data);
+                       if (network_info && network_info->event_callback)
+                               network_info->event_callback(event_data, network_info->user_data);
                        g_free(event_data);
                        break;
                }
@@ -414,7 +431,8 @@ static int __net_handle_service_state_changed(network_info_t *network_info,
 
                        NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_RSP");
 
-                       network_info->event_callback(event_data, network_info->user_data);
+                       if (network_info && network_info->event_callback)
+                               network_info->event_callback(event_data, network_info->user_data);
                        g_free(event_data);
                        break;
                }
@@ -429,7 +447,8 @@ static int __net_handle_service_state_changed(network_info_t *network_info,
 
                NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_IND");
 
-               network_info->event_callback(event_data, network_info->user_data);
+               if (network_info && network_info->event_callback)
+                       network_info->event_callback(event_data, network_info->user_data);
                g_free(event_data);
                break;
        }
@@ -486,6 +505,12 @@ static int __net_handle_ethernet_cable_state_rsp(GVariant *param,
        const gchar *sig_value = NULL;
        net_event_info_t *event_data = NULL;
 
+       if (network_info == NULL ||
+               network_info->event_callback == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
        g_variant_get(param, "(a{sv})", &iter);
 
        while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
@@ -589,6 +614,12 @@ static int __net_handle_network_config_changed_event(GVariant *param,
        int network_status;
        gchar *params_str = NULL;
 
+       if (network_info == NULL ||
+               network_info->event_callback == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
        params_str = g_variant_print(param, TRUE);
        NETWORK_LOG(NETWORK_LOW, "params %s", params_str);
        g_variant_get(param, "(a{sv})", &iter);
@@ -724,6 +755,12 @@ static int __net_handle_wifi_connect_fail_event(GVariant *param, network_info_t
        network_request_table_t *wps_info =
                        &request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS];
 
+       if (network_info == NULL ||
+               network_info->event_callback == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
        event_data = g_try_new0(net_event_info_t, 1);
        if (event_data == NULL) {
                __NETWORK_FUNC_EXIT__;
@@ -838,10 +875,12 @@ void _net_set_cs_tid(int tid, network_info_t *network_info)
                cs_tid_list = g_slist_prepend(cs_tid_list, tid_info);
        }
 
-       tid_info->subscribe_id_connman_state = network_info->subscribe_id_connman_state;
-       tid_info->subscribe_id_connman_error = network_info->subscribe_id_connman_error;
-       tid_info->subscribe_id_netconfig_wifi = network_info->subscribe_id_netconfig_wifi;
-       tid_info->subscribe_id_netconfig = network_info->subscribe_id_netconfig;
+       if (network_info) {
+               tid_info->subscribe_id_connman_state = network_info->subscribe_id_connman_state;
+               tid_info->subscribe_id_connman_error = network_info->subscribe_id_connman_error;
+               tid_info->subscribe_id_netconfig_wifi = network_info->subscribe_id_netconfig_wifi;
+               tid_info->subscribe_id_netconfig = network_info->subscribe_id_netconfig;
+       }
 
        NETWORK_LOG(NETWORK_HIGH, "tid %d, tid_info %p", tid, tid_info);
 }
@@ -867,14 +906,16 @@ void _net_unset_cs_tid(int tid, network_info_t *network_info)
                return;
        }
 
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               tid_info->subscribe_id_connman_state);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               tid_info->subscribe_id_connman_error);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               tid_info->subscribe_id_netconfig_wifi);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               tid_info->subscribe_id_netconfig);
+       if (network_info) {
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       tid_info->subscribe_id_connman_state);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       tid_info->subscribe_id_connman_error);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       tid_info->subscribe_id_netconfig_wifi);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       tid_info->subscribe_id_netconfig);
+       }
 
        NETWORK_LOG(NETWORK_HIGH, "tid %d, tid_info %p", tid, tid_info);
 
@@ -887,16 +928,18 @@ void _net_deregister_signal(network_info_t *network_info)
 {
        __NETWORK_FUNC_ENTER__;
 
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               network_info->subscribe_id_connman_state);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               network_info->subscribe_id_mesh_state);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               network_info->subscribe_id_connman_error);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               network_info->subscribe_id_netconfig_wifi);
-       g_dbus_connection_signal_unsubscribe(network_info->connection,
-                               network_info->subscribe_id_netconfig);
+       if (network_info) {
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       network_info->subscribe_id_connman_state);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       network_info->subscribe_id_mesh_state);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       network_info->subscribe_id_connman_error);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       network_info->subscribe_id_netconfig_wifi);
+               g_dbus_connection_signal_unsubscribe(network_info->connection,
+                                       network_info->subscribe_id_netconfig);
+       }
 
        __NETWORK_FUNC_EXIT__;
 }
@@ -907,6 +950,11 @@ int _net_register_signal(network_info_t *network_info)
 
        net_err_t Error = NET_ERR_NONE;
 
+       if (network_info == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
        /* Create connman service state connection */
        network_info->subscribe_id_connman_state = g_dbus_connection_signal_subscribe(
                        network_info->connection,