Fix double close issue 64/224364/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 10 Feb 2020 06:24:00 +0000 (15:24 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 10 Feb 2020 06:24:00 +0000 (15:24 +0900)
fd passed to fdopendir is used internally by the implementation, and
should not otherwise be used by the application.

Change-Id: Ib8de3e9782f8e2455329acaecaeb43d2646c3a6d
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/pkg_getsize.c

index 94ebd66..b459c2c 100644 (file)
@@ -157,6 +157,16 @@ static long long __calculate_directory_size(int dfd, bool include_itself)
                size += __stat_size(&st);
        }
 
+       /* fd passed to fdopendir is used internally by the implementation,
+        * and should not otherwise be used by the application.
+        * So we need to pass duplicated fd to fdopendir.
+        */
+       dfd = dup(dfd);
+       if (dfd == -1) {
+               LOGE("failed to duplicate fd, errno: %d (%s)", errno,
+                               strerror_r(errno, buf, sizeof(buf)));
+               return -1;
+       }
        dir = fdopendir(dfd);
        if (dir == NULL) {
                LOGE("fdopendir() failed, errno: %d (%s)", errno,