summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_file.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-08-21 08:50:05 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-08-21 09:18:23 +0100
commit49662fcb494b551c4acec090d60a0192c2a9384e (patch)
tree7a6ec654499fb014c07a396aa8929bdd9dafaeae /src/lib/eina/eina_file.c
parent0601cda0ba4e7600eb44a8837616cd015354349f (diff)
eina - eina_file_close_from - handle coverity theory that closes change
this won't happen as the setup should not have the # of fd's found in 2st pass and 2nd pass for a dirfd change as nothing should interfere. comment to that effect and add a paranoid change num_closes to the number found
Diffstat (limited to '')
-rw-r--r--src/lib/eina/eina_file.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index e38bf5bfbb..c5e1f1a0b8 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -1315,6 +1315,9 @@ eina_file_close_from(int fd, int *except_fd)
1315 ssize_t pos, ret; 1315 ssize_t pos, ret;
1316 Eina_Bool do_read; 1316 Eina_Bool do_read;
1317 1317
1318 // note - this api is EXPECTED to be called in between a fork() and exec()
1319 // when no threads are running. if you use this outside that context then
1320 // it may not work as intended and may miss some fd's etc.
1318 dirfd = open("/proc/self/fd", O_RDONLY | O_DIRECTORY); 1321 dirfd = open("/proc/self/fd", O_RDONLY | O_DIRECTORY);
1319 if (dirfd < 0) dirfd = open("/dev/fd", O_RDONLY | O_DIRECTORY); 1322 if (dirfd < 0) dirfd = open("/dev/fd", O_RDONLY | O_DIRECTORY);
1320 if (dirfd >= 0) 1323 if (dirfd >= 0)
@@ -1384,6 +1387,11 @@ skip2:
1384 if (clo < num_closes) closes[clo] = num; 1387 if (clo < num_closes) closes[clo] = num;
1385 clo++; 1388 clo++;
1386 } 1389 }
1390 // in case we somehow don't fill up all of closes in 2nd pass
1391 // (this shouldn't happen as no threads are running and we
1392 // do nothing to modify the fd set between 2st and 2nd pass).
1393 // set rest num_closes to clo so we don't close invalid values
1394 num_closes = clo;
1387 } 1395 }
1388 close(dirfd); 1396 close(dirfd);
1389 // now go close all those fd's - some may be invalide like the dir 1397 // now go close all those fd's - some may be invalide like the dir