[FIX] prevent issue 58/30258/1
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 13 Nov 2014 10:41:10 +0000 (13:41 +0300)
committerVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 13 Nov 2014 10:41:10 +0000 (13:41 +0300)
|------------------------|-------------------|
| Type                   | Function          |
|------------------------|-------------------|
| Calling risky function | close_on_exec_dup |
| Calling risky function | remove_indir      |
|------------------------|-------------------|

Change-Id: I3bdd110fbbb7ac2abe049a2045e73b28b6917417
S-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
daemon/da_debug.c
daemon/utils.c

index 782410c..0315511 100644 (file)
@@ -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 {
index 05d3374..2dbefae 100644 (file)
@@ -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);