From: hyunuktak Date: Fri, 11 Dec 2015 06:09:37 +0000 (+0900) Subject: Fix some prevents for VD-Critical X-Git-Tag: submit/tizen/20151211.070127^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0e799b8f18ec2f75c02f221f782e1f9a469de0d1;p=platform%2Fcore%2Fconnectivity%2Fnet-config.git Fix some prevents for VD-Critical Change-Id: I0fcf138f97bccf8b9e62f45e905112a7829c1299 Signed-off-by: hyunuktak --- diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 5734dc0..7ea2392 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.46 +Version: 1.1.47 Release: 2 Group: System/Network License: Apache-2.0 diff --git a/src/utils/log.c b/src/utils/log.c index dfe2bb4..7a358f6 100755 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -74,17 +74,16 @@ static inline void __netconfig_log_make_backup(void) static inline void __netconfig_log_get_local_time(char *strtime, const int size) { - struct timeval tv; + time_t buf; struct tm *local_ptm; - char buf[32]; + struct tm result = {0, }; - gettimeofday(&tv, NULL); - local_ptm = localtime(&tv.tv_sec); + time(&buf); + buf = time(NULL); + local_ptm = localtime_r(&buf, &result); - if(local_ptm) - strftime(buf, sizeof(buf), "%m/%d %H:%M:%S", local_ptm); - - snprintf(strtime, size, "%s.%03ld", buf, tv.tv_usec / 1000); + if (local_ptm) + strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm); } void netconfig_log(const char *format, ...) diff --git a/src/utils/util.c b/src/utils/util.c index f83252d..8dc93c2 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -397,6 +397,7 @@ int netconfig_execute_file(const char *file_path, int rv = 0; errno = 0; register unsigned int index = 0; + char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, }; while (args[index] != NULL) { DBG("%s", args[index]); @@ -409,7 +410,8 @@ int netconfig_execute_file(const char *file_path, errno = 0; if (execve(file_path, args, envs) == -1) { - DBG("Fail to execute command (%s)", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Fail to execute command (%s)", error_buf); exit(1); } } else if (pid > 0) { @@ -430,7 +432,8 @@ int netconfig_execute_file(const char *file_path, return rv; } - DBG("failed to fork(%s)", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("failed to fork(%s)", error_buf); return -EIO; } @@ -450,6 +453,7 @@ int netconfig_execute_clatd(const char *file_path, char *const args[]) int rv = 0; errno = 0; register unsigned int index = 0; + char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, }; struct sigaction act; int state = 0; @@ -475,7 +479,8 @@ int netconfig_execute_clatd(const char *file_path, char *const args[]) errno = 0; if (execvp(file_path, args) == -1) { - ERR("Fail to execute command (%s)", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + ERR("Fail to execute command (%s)", error_buf); return -1; } } else if (pid > 0) { @@ -483,7 +488,8 @@ int netconfig_execute_clatd(const char *file_path, char *const args[]) return rv; } - DBG("failed to fork(%s)", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("failed to fork(%s)", error_buf); return -EIO; } @@ -492,6 +498,7 @@ int __netconfig_get_interface_index(const char *interface_name) struct ifreq ifr; int sock = 0; int result = 0; + char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, }; if (interface_name == NULL) { DBG("Inteface name is NULL"); @@ -501,7 +508,8 @@ int __netconfig_get_interface_index(const char *interface_name) errno = 0; sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sock < 0) { - DBG("Failed to create socket : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to create socket : %s", error_buf); return -1; } @@ -511,7 +519,7 @@ int __netconfig_get_interface_index(const char *interface_name) close(sock); if (result < 0) { - DBG("Failed to get ifr index: %s", strerror(errno)); + DBG("Failed to get ifr index: %s", error_buf); return -1; } @@ -524,6 +532,7 @@ int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gi struct rtentry rt; struct sockaddr_in addr_in; int sock; + char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, }; memset(&ifr, 0, sizeof(ifr)); @@ -558,12 +567,14 @@ int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gi sock = socket(PF_INET, SOCK_DGRAM, 0); if (sock < 0) { - DBG("Failed to create socket : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to create socket : %s", error_buf); return -1; } if (ioctl(sock, SIOCADDRT, &rt) < 0) { - DBG("Failed to set route address : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to set route address : %s", error_buf); close(sock); return -1; } @@ -579,6 +590,7 @@ int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gi struct rtentry rt; struct sockaddr_in addr_in; int sock; + char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, }; memset(&ifr, 0, sizeof(ifr)); ifr.ifr_ifindex = __netconfig_get_interface_index(interface); @@ -606,12 +618,14 @@ int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gi sock = socket(PF_INET, SOCK_DGRAM, 0); if (sock < 0) { - DBG("Failed to create socket : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to create socket : %s", error_buf); return -1; } if (ioctl(sock, SIOCDELRT, &rt) < 0) { - DBG("Failed to set route address : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to set route address : %s", error_buf); close(sock); return -1; } @@ -626,6 +640,7 @@ int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u struct in6_rtmsg rt; int fd = 0; int err = 0; + char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, }; memset(&rt, 0, sizeof(rt)); @@ -635,14 +650,16 @@ int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u errno = 0; if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) { - DBG("inet_pton failed : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("inet_pton failed : %s", error_buf); return -1; } if (gateway != NULL) { rt.rtmsg_flags |= RTF_GATEWAY; if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) { - DBG("inet_pton failed : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("inet_pton failed : %s", error_buf); return -1; } } @@ -651,7 +668,8 @@ int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u fd = socket(AF_INET6, SOCK_DGRAM, 0); if (fd < 0) { - DBG("Failed to create socket : %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to create socket : %s", error_buf); return -1; } @@ -666,7 +684,8 @@ int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u } if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) { - DBG("Failed to add route: %s", strerror(errno)); + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); + DBG("Failed to add route: %s", error_buf); close(fd); return -1; } diff --git a/src/wifi-config.c b/src/wifi-config.c index f6dfe44..d40e6d8 100755 --- a/src/wifi-config.c +++ b/src/wifi-config.c @@ -485,7 +485,8 @@ static gboolean _get_field(const gchar *config_id, const gchar *key, gchar **val static GSList *_get_list(void) { GSList *list = NULL; - struct dirent *d; + struct dirent ent_struct; + struct dirent *dp = NULL; DIR *dir; dir = opendir(CONNMAN_STORAGE); @@ -494,12 +495,12 @@ static GSList *_get_list(void) return NULL; } - while ((d = readdir(dir))) { - if (g_strcmp0(d->d_name, ".") == 0 || g_strcmp0(d->d_name, "..") == 0 || - strncmp(d->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) { + while ((readdir_r(dir, &ent_struct, &dp) == 0) && dp) { + if (g_strcmp0(dp->d_name, ".") == 0 || g_strcmp0(dp->d_name, "..") == 0 || + strncmp(dp->d_name, WIFI_CONFIG_PREFIX, strlen(WIFI_CONFIG_PREFIX)) != 0) { continue; } - gchar *config_id = g_strdup(d->d_name + WIFI_PREFIX_LENGTH); + gchar *config_id = g_strdup(dp->d_name + WIFI_PREFIX_LENGTH); list = g_slist_append(list, g_strdup(config_id)); g_free(config_id); } diff --git a/src/wifi-indicator.c b/src/wifi-indicator.c index 6653d84..2fbfef6 100755 --- a/src/wifi-indicator.c +++ b/src/wifi-indicator.c @@ -100,16 +100,17 @@ static int __netconfig_wifi_update_and_get_rssi(void) continue; /* read wireless status */ - p_entry = strtok(p_entry, " ."); // status "%x" + char *saveptr; + p_entry = strtok_r(p_entry, " .", &saveptr); // status "%x" if (p_entry != NULL) sscanf(p_entry, "%x", &status); - p_entry = strtok(NULL, " ."); // Quality link "%d" + p_entry = strtok_r(NULL, " .", &saveptr); // Quality link "%d" if (p_entry != NULL) sscanf(p_entry, "%d", &link); - p_entry = strtok(NULL, " ."); // Quality level "%d" + p_entry = strtok_r(NULL, " .", &saveptr); // Quality level "%d" if (p_entry != NULL) sscanf(p_entry, "%d", &rssi_dbm); - p_entry = strtok(NULL, " ."); // Quality noise "%d" + p_entry = strtok_r(NULL, " .", &saveptr); // Quality noise "%d" if (p_entry != NULL) sscanf(p_entry, "%d", &noise); diff --git a/src/wifi-power.c b/src/wifi-power.c index 3b8df97..8f203fe 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -1242,7 +1242,7 @@ void __netconfig_set_ether_macaddr() rand_mac_add[0] |= 0x02; /*set local assignment bit*/ /*Set the Mac address in Vconf*/ - sprintf(mac_addr, "%x:%x:%x:%x:%x:%x", + sprintf_s(mac_addr, WLAN_MAC_ADDR_MAX, "%x:%x:%x:%x:%x:%x", rand_mac_add[0], rand_mac_add[1], rand_mac_add[2], rand_mac_add[3], rand_mac_add[4], rand_mac_add[5]);