From 2173220ff57b812e829ed2a4aab0617bb37ad927 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Fri, 16 Mar 2018 10:07:04 +0900 Subject: [PATCH] Fixed some coverity Resource leak Uninitialized scalar variable Memset fill value of '0' Buffer not null terminated Various Change-Id: I265d50163bb56ada269cf7206b9d0bad333b57f6 Signed-off-by: hyunuktak --- packaging/net-config.spec | 2 +- src/signal-handler.c | 7 ++++--- src/vpnsvc-internal.c | 38 +++++++++++++++++++------------------- src/vpnsvc.c | 5 +++++ src/wifi-config.c | 1 + src/wifi-key-encryption.c | 2 ++ src/wifi-netlink-scan.c | 7 ++++++- src/wifi-passpoint.c | 6 ++---- src/wifi-power.c | 13 +++---------- src/wifi-wps.c | 4 +--- 10 files changed, 44 insertions(+), 41 deletions(-) diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 6ed9250..7734ddd 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.125 +Version: 1.1.126 Release: 3 Group: System/Network License: Apache-2.0 diff --git a/src/signal-handler.c b/src/signal-handler.c index 96cdc56..1d488df 100755 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -231,7 +231,8 @@ static void _technology_signal_cb(GDBusConnection *conn, static void _service_signal_cb(GDBusConnection *conn, const gchar *name, const gchar *path, - const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) + const gchar *interface, const gchar *sig, + GVariant *param, gpointer user_data) { gchar *sigvalue = NULL; gchar *property; @@ -858,8 +859,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; diff --git a/src/vpnsvc-internal.c b/src/vpnsvc-internal.c index 87add01..b4cbafb 100755 --- a/src/vpnsvc-internal.c +++ b/src/vpnsvc-internal.c @@ -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) { diff --git a/src/vpnsvc.c b/src/vpnsvc.c index 8b126ed..8ed0608 100755 --- a/src/vpnsvc.c +++ b/src/vpnsvc.c @@ -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) { diff --git a/src/wifi-config.c b/src/wifi-config.c index 09404e7..51981b7 100755 --- a/src/wifi-config.c +++ b/src/wifi-config.c @@ -692,6 +692,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; } diff --git a/src/wifi-key-encryption.c b/src/wifi-key-encryption.c index d57bce1..e8a9f36 100755 --- a/src/wifi-key-encryption.c +++ b/src/wifi-key-encryption.c @@ -205,6 +205,7 @@ gchar* _netconfig_encrypt_passphrase(const gchar *passphrase) g_free(origin_value)); if (__netconfig_set_param_list_aes_gcm(param) == NULL) { + ckmc_param_list_free(param); g_free(origin_value); return NULL; } @@ -261,6 +262,7 @@ static gchar* _netconfig_decrypt_passphrase(const gchar *enc_data) g_free(ehexstr)); if (__netconfig_set_param_list_aes_gcm(param) == NULL) { + ckmc_param_list_free(param); g_free(ehexstr); return NULL; } diff --git a/src/wifi-netlink-scan.c b/src/wifi-netlink-scan.c index 2876170..d60f7ea 100755 --- a/src/wifi-netlink-scan.c +++ b/src/wifi-netlink-scan.c @@ -303,14 +303,17 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) int signal; bss_info = g_try_new0(struct bss_scan_info_t, 1); - if (bss_info == NULL) + if (bss_info == NULL) { + g_free(vsie); return NL_SKIP; + } g_strlcpy(bss_info->bssid, bssid, strlen(bssid)+1); g_strlcpy(bss_info->ssid, ssid, strlen(ssid)+1); if (vsie) { g_strlcpy(bss_info->vsie, vsie, strlen(vsie)+1); g_free(vsie); + vsie = NULL; } bss_info->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); @@ -328,6 +331,7 @@ static int __netconfig_netlink_scan_cb(struct nl_msg *msg, void *user_data) } + g_free(vsie); return NL_SKIP; } @@ -444,6 +448,7 @@ static int __netconfig_request_netlink_scan(struct nl_sock *socket, if (ret < 0) { DBG("nl_recvmsgs() ret: %d (%s)", ret, nl_geterror(-ret)); + nl_cb_put(cb); return ret; } diff --git a/src/wifi-passpoint.c b/src/wifi-passpoint.c index c7f62be..2e84b32 100755 --- a/src/wifi-passpoint.c +++ b/src/wifi-passpoint.c @@ -64,12 +64,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); diff --git a/src/wifi-power.c b/src/wifi-power.c index 2ab8f4b..6ed9e8f 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -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, diff --git a/src/wifi-wps.c b/src/wifi-wps.c index 95e8d40..2a80959 100755 --- a/src/wifi-wps.c +++ b/src/wifi-wps.c @@ -208,10 +208,8 @@ static gboolean __netconfig_wifi_invoke_wps_process_credentials(char *object_pat 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, -- 2.34.1