Fix the svace issue (182949, 182950, ...) 94/116894/1 accepted/tizen/3.0/common/20170303.085752 accepted/tizen/3.0/ivi/20170303.073709 accepted/tizen/3.0/mobile/20170303.073612 accepted/tizen/3.0/wearable/20170303.073653 submit/tizen_3.0/20170302.051403
authorLee Hyuk <hyuk0512.lee@samsung.com>
Thu, 2 Mar 2017 01:26:21 +0000 (10:26 +0900)
committerLee Hyuk <hyuk0512.lee@samsung.com>
Thu, 2 Mar 2017 01:26:21 +0000 (10:26 +0900)
Change-Id: I7cc5b8d1d2afbc4ce9303497c7da4f35ef5a244b
Signed-off-by: Lee Hyuk <hyuk0512.lee@samsung.com>
bt-ipsp/bt-ipsp.c

index bc8b870..32a889e 100644 (file)
@@ -230,7 +230,7 @@ gboolean __bt_ipsp_get_network_ipv6_address(const char *if_name, mobile_ap_ipv6_
                if (scope != ip_scope)
                        continue;
 
-               sprintf(copied, "%s:%s:%s:%s:%s:%s:%s:%s",
+               snprintf(copied, sizeof(copied), "%s:%s:%s:%s:%s:%s:%s:%s",
                                addr[0], addr[1], addr[2], addr[3],
                                addr[4], addr[5], addr[6], addr[7]);
 
@@ -272,7 +272,7 @@ int __bt_ipsp_create_ipv6_address(char *ifname, char **ipv6_address)
                strtok_r(link_addr, ":", &if_id);
                link_addr = if_id;
        }
-       sprintf(copied, "%s:%s", prefix, if_id);
+       snprintf(copied, sizeof(copied), "%s:%s", prefix, if_id);
 
        *ipv6_address = g_strdup(copied);
 
@@ -281,11 +281,11 @@ int __bt_ipsp_create_ipv6_address(char *ifname, char **ipv6_address)
        g_free(network_if_name);
        g_free(link_addr);
        g_free(network_addr);
-       g_free(prefix);
        g_free(if_id);
 #endif
        BT_DBG("Created IPv6 address [%s]", *ipv6_address);
 
+       g_free(prefix);
        return BT_ERROR_NONE;
 
 }
@@ -306,12 +306,13 @@ int __bt_ipsp_set_ipv6_address(const char *if_name, char *ipv6_addr)
 
        g_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
 
-       memset(&addr, 0, sizeof(struct sockaddr));
+       memset(&addr, 0, sizeof(struct sockaddr_in6));
        addr.sin6_family = AF_INET6;
        addr.sin6_port = 0;
 
        if (inet_pton(AF_INET6, ipv6_addr, (void *)&addr.sin6_addr) <= 0) {
                BT_ERR("Bad address!!");
+               close(sock_fd);
                return BT_ERROR_OPERATION_FAILED;
        }
 
@@ -414,6 +415,7 @@ int __bt_ipsp_execute_dhcp6_server(void)
        pid_t pid;
        char *network_if_name = NULL;
        char *network_addr = NULL;
+       char *address = NULL;
 
        if (remove(DNSMASQ_LEASES_FILE) < 0)
                BT_ERR("Failed to remove %s", DNSMASQ_LEASES_FILE);
@@ -430,16 +432,19 @@ int __bt_ipsp_execute_dhcp6_server(void)
                __bt_ipsp_get_network_ipv6_address(network_if_name, MOBILE_AP_IPV6_SCOPE_GLOBAL, &network_addr);
                if (network_addr == NULL) {
                        BT_ERR("Failed to get global IP");
+                       fclose(fp);
                        return BT_ERROR_OPERATION_FAILED;
                }
 
-               snprintf(buf, DNSMASQ_CONF_LEN, DNSMASQ_CONF6, dns_addr, g_strndup(network_addr, 19));
+               address = g_strndup(network_addr, 19);
+               snprintf(buf, DNSMASQ_CONF_LEN, DNSMASQ_CONF6, dns_addr, address);
                fputs(buf, fp);
                fclose(fp);
 
                pid = fork();
                if (pid < 0) {
                        BT_ERR("fork failed\n");
+                       g_free(address);
                        return BT_ERROR_OPERATION_FAILED;
                }
 
@@ -493,7 +498,7 @@ static void __generate_eui64_address(char *hw_addr, char **eui64_addr)
        /* Invert 7th bit */
        hex ^= 2;
        BT_DBG("Inverted bit(%x)", hex);
-       sprintf(addr64, "%x%s:%sff:fe%s:%s%s",
+       snprintf(addr64, sizeof(addr64), "%x%s:%sff:fe%s:%s%s",
                        hex, addr[1], addr[2], addr[3], addr[4], addr[5]);
 
        BT_DBG("addr64(%s)", addr64);
@@ -505,7 +510,6 @@ static void __generate_eui64_address(char *hw_addr, char **eui64_addr)
        BT_DBG("-");
 }
 
-
 int __bt_ipsp_create_ipv6_remote_address(char *remote_address, char **ipv6_address)
 {
        BT_DBG("++");
@@ -529,14 +533,13 @@ int __bt_ipsp_create_ipv6_remote_address(char *remote_address, char **ipv6_addre
        }
 
        prefix = g_strndup(network_addr, 19);
-       sprintf(copied, "%s:%s", prefix, eui64_addr);
+       snprintf(copied, sizeof(copied), "%s:%s", prefix, eui64_addr);
        *ipv6_address = g_strdup(copied);
-
        BT_DBG("remote device ipv6 addr : %s", *ipv6_address);
+
+       g_free(prefix);
        BT_DBG("--");
        return BT_ERROR_NONE;
-
-
 }
 
 int _execute_command(const char *cmd)