From: Vitaliy Cherepanov Date: Thu, 13 Nov 2014 10:41:10 +0000 (+0300) Subject: [FIX] prevent issue X-Git-Tag: submit/tizen/20151105.065919~92 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d97d427f9213a1a4a0a7a6dcfb4d75ff2fc1bd7;p=platform%2Fcore%2Fsystem%2Fswap-manager.git [FIX] prevent issue |------------------------|-------------------| | Type | Function | |------------------------|-------------------| | Calling risky function | close_on_exec_dup | | Calling risky function | remove_indir | |------------------------|-------------------| Change-Id: I3bdd110fbbb7ac2abe049a2045e73b28b6917417 S-by: Vitaliy Cherepanov --- diff --git a/daemon/da_debug.c b/daemon/da_debug.c index 782410c..0315511 100644 --- a/daemon/da_debug.c +++ b/daemon/da_debug.c @@ -49,14 +49,14 @@ static inline int close_on_exec_dup(int old, int new) if (dup2(old, new) != -1) { unsigned long flags = fcntl(new, F_GETFD); if (flags == -1) { - LOGE("can not get flags fd #%d <%s>\n", new, - strerror(errno)); + LOGE("can not get flags fd #%d errno <%d>\n", new, + errno); goto err_ret; } if (fcntl(new, F_SETFD, flags | FD_CLOEXEC) == -1) { - LOGE("can not get flags fd #%d <%s>\n", new, - strerror(errno)); + LOGE("can not get flags fd #%d errno <%d>\n", new, + errno); goto err_ret; } } else { diff --git a/daemon/utils.c b/daemon/utils.c index 05d3374..2dbefae 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -109,6 +109,8 @@ int remove_indir(const char *dirname) { DIR *dir; struct dirent *entry; + static char dirent_buffer[ sizeof(struct dirent) + PATH_MAX + 1 ] = {0,}; + static struct dirent *dirent_r = (struct dirent *)dirent_buffer; char path[PATH_MAX]; dir = opendir(dirname); @@ -117,8 +119,7 @@ int remove_indir(const char *dirname) return -1; } - while((entry = readdir(dir)) != NULL) - { + while ((readdir_r(dir, dirent_r, &entry) == 0) && entry) { if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) { snprintf(path, (size_t) PATH_MAX, "%s/%s", dirname, entry->d_name);