Fixed coverity issues 36/196736/12 accepted/tizen/4.0/unified/20190104.230826 submit/tizen_4.0/20190104.100529
authorhyunuktak <hyunuk.tak@samsung.com>
Fri, 4 Jan 2019 04:13:44 +0000 (13:13 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Fri, 4 Jan 2019 05:19:25 +0000 (14:19 +0900)
Change-Id: I8a02791d62c217c64e1e52a34c5ea3b5f61cd450
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
packaging/net-config.spec
src/network-state.c
src/signal-handler.c
src/vpnsvc-internal.c
src/vpnsvc.c
src/wifi-config.c
src/wifi-passpoint.c
src/wifi-power.c
src/wifi-wps.c

index 1939b0f..9be9340 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          net-config
 Summary:       TIZEN Network Configuration service
-Version:       1.1.118
+Version:       1.1.119
 Release:       2
 Group:         System/Network
 License:       Apache-2.0
index 33bc1c7..408d4fc 100755 (executable)
@@ -551,6 +551,7 @@ static char *__netconfig_get_preferred_ipv6_address(char *profile)
                                if (g_strcmp0(sub_key, "Address") == 0) {
                                        value = g_variant_get_string(variant, NULL);
                                        preferred_address6 = g_strdup(value);
+                                       break;
                                }
                        }
                        g_variant_iter_free(sub_iter);
@@ -1161,7 +1162,8 @@ char *netconfig_get_ifname(const char *profile)
                        while (g_variant_iter_loop(next, "{sv}", &key1, &variant)) {
                                if (g_strcmp0(key1, "Interface") == 0) {
                                        value = g_variant_get_string(variant, NULL);
-                                       ifname = g_strdup(value);
+                                       if (!ifname)
+                                               ifname = g_strdup(value);
                                        g_free(key1);
                                        g_variant_unref(variant);
                                        break;
index ca53b28..b0a0761 100755 (executable)
@@ -728,8 +728,8 @@ error:
 static void _supplicant_wifi_wps_credentials(GVariant *param)
 {
        gchar *key;
-       char ssid[32];
-       char wps_key[100];
+       char ssid[32] = {0, };
+       char wps_key[100] = {0, };
        GVariantIter *iter;
        GVariant *variant;
        int config_error = 0;
index 87add01..b4cbafb 100755 (executable)
@@ -507,13 +507,13 @@ static void dns_nat_unregister(void)
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN_FROM_NAT,
                        iptables_cmd, iptables_nat_chain_name);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN_FROM_NAT,
                        iptables_cmd, iptables_nat_chain_name);
        if (netconfig_execute_cmd(buf))
@@ -532,55 +532,55 @@ static void iptables_register(void)
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_DROP_RULE,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_RETURN_RULE,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_INSERT_RULE,
                        iptables_cmd, filter, iptables_filter_prefix, filter);
 
        filter = iptables_filter_in;
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_CREATE_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_DROP_RULE,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_RETURN_RULE,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_INSERT_RULE,
                        iptables_cmd, filter, iptables_filter_prefix, filter);
 }
@@ -597,13 +597,13 @@ static void iptables_unregister(void)
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
@@ -611,19 +611,19 @@ static void iptables_unregister(void)
 
        filter = iptables_filter_in;
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_RULE,
                        iptables_cmd, filter, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN,
                        iptables_cmd, iptables_filter_prefix, filter);
        if (netconfig_execute_cmd(buf))
@@ -640,7 +640,7 @@ static void iptables_rule(const char c, const char *addr, const int mask)
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_ACCEPT_RULE,
                        iptables_cmd, c,  iptables_filter_prefix,
                        iptables_filter_in, 's', addr, mask);
@@ -658,7 +658,7 @@ static void iptables_rule_interface(const char c, const char *addr, const int ma
        if (netconfig_execute_cmd(buf))
                ERR("Failed to execute command: %s", buf);
 
-       memset(buf, '0', sizeof(buf));
+       memset(buf, 0, sizeof(buf));
        snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_ACCEPT_RULE_WITH_INTF,
                        iptables_cmd, c, iptables_filter_prefix, iptables_filter_in,
                        'i', interface, 's', addr, mask);
@@ -703,7 +703,7 @@ static int get_interface_index(const char *iface_name)
        memset(&ifr, 0, sizeof(ifr));
 
        if (*iface_name)
-               strncpy(ifr.ifr_name, iface_name, IFNAMSIZ);
+               strncpy(ifr.ifr_name, iface_name, IFNAMSIZ - 1);
 
        /* get an interface name by ifindex */
        if (ioctl(sk, SIOCGIFINDEX, &ifr) < 0) {
index 8b126ed..8ed0608 100755 (executable)
@@ -169,6 +169,11 @@ gboolean handle_vpn_block_networks(Vpnsvc *object,
 
        DBG("vpn_block_networks");
 
+       memset(nets_vpn, 0, sizeof(char *) * arg_nr_nets_vpn);
+       memset(prefix_vpn, 0, sizeof(int) * arg_nr_nets_vpn);
+       memset(nets_orig, 0, sizeof(char *) * arg_nr_nets_vpn);
+       memset(prefix_orig, 0, sizeof(int) * arg_nr_nets_vpn);
+
        /* arg_nets_vpn check */
        if (arg_nr_nets_vpn > 0) {
                if (arg_nets_vpn != NULL) {
index a53f705..a81285f 100755 (executable)
@@ -165,6 +165,7 @@ static gboolean __get_group_name(const gchar *prefix, const gchar *config_id, gc
        ret = __get_mac_address(&mac_address);
        if ((ret != TRUE) || (strlen(mac_address) == 0)) {
                ERR("Cannot get WIFI MAC address");
+               g_free(mac_address);
                return FALSE;
        }
 
@@ -692,6 +693,7 @@ static int __netconfig_unpack_ay_malloc(unsigned char **dst, GVariantIter *iter)
        tmp_dst = (unsigned char *)g_try_malloc0(length + 1);
        if (!tmp_dst) {
                ERR("failed to allocate memory");
+               g_variant_iter_free(iter_copy);
                return 0;
        }
 
index 8a43cc9..59f6b32 100755 (executable)
@@ -59,12 +59,10 @@ static gboolean netconfig_wifi_set_passpoint(gint32 enable)
 {
        gint32 value = enable ? 1 : 0;
        gboolean result = FALSE;
-       GVariant *input_args = NULL;
-
-       input_args = g_variant_new_int32(value);
 
        result = netconfig_supplicant_invoke_dbus_interface_property_set(
-                       SUPPLICANT_IFACE_INTERFACE, "Passpoint", input_args, NULL);
+                       SUPPLICANT_IFACE_INTERFACE, "Passpoint",
+                       g_variant_new_int32(value), NULL);
        if (result == FALSE)
                ERR("Fail to set passpoint enable[%d]", enable);
 
index 81e0eac..2d45e84 100755 (executable)
@@ -221,7 +221,6 @@ static gboolean __check_and_set_technology_enable(gpointer data)
        static int retry_count = NETCONFIG_TECH_WAITING_COUNT;
        gboolean value_enable = TRUE;
        gboolean reply = FALSE;
-       GVariant *param0 = NULL;
        GVariant *params = NULL;
        char key[] = "Powered";
 
@@ -231,8 +230,7 @@ static gboolean __check_and_set_technology_enable(gpointer data)
                        return TRUE;
        }
 
-       param0 = g_variant_new_boolean(value_enable);
-       params = g_variant_new("(sv)", key, param0);
+       params = g_variant_new("(sv)", key, g_variant_new_boolean(value_enable));
 
        reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
                                        CONNMAN_WIFI_TECHNOLOGY_PREFIX,
@@ -254,7 +252,6 @@ static gboolean __check_and_set_technology_enable(gpointer data)
 static int _set_connman_technology_power(gboolean enable)
 {
        gboolean reply = FALSE;
-       GVariant *param0 = NULL;
        GVariant *params = NULL;
        char key[] = "Powered";
        gboolean value_enable = TRUE;
@@ -270,12 +267,8 @@ static int _set_connman_technology_power(gboolean enable)
                return 0;
        }
 
-       if (enable == TRUE)
-               param0 = g_variant_new_boolean(value_enable);
-       else
-               param0 = g_variant_new_boolean(value_disable);
-
-       params = g_variant_new("(sv)", key, param0);
+       params = g_variant_new("(sv)", key, (enable == TRUE) ?
+               g_variant_new_boolean(value_enable) : g_variant_new_boolean(value_disable));
 
        reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
                                        CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE,
index 5f09eb7..729f0a7 100755 (executable)
@@ -209,10 +209,8 @@ static gboolean __netconfig_wifi_invoke_wps_process_credentials(const char *obje
        const char *interface = SUPPLICANT_IFACE_WPS;
        const char *key = "ProcessCredentials";
        gboolean credentials = TRUE;
-       GVariant *var = NULL;
 
-        var = g_variant_new_boolean(credentials);
-       params = g_variant_new("(ssv)", interface, key, var);
+       params = g_variant_new("(ssv)", interface, key, g_variant_new_boolean(credentials));
 
        INFO("[net-config]: TizenMW-->WPAS: .Set");
        reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE,