raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=49662fcb494b551c4acec090d60a0192c2a9384e

commit 49662fcb494b551c4acec090d60a0192c2a9384e
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Fri Aug 21 08:50:05 2020 +0100

    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
---
 src/lib/eina/eina_file.c | 8 ++++++++
 1 file changed, 8 insertions(+)

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)
    ssize_t pos, ret;
    Eina_Bool do_read;
 
+   // note - this api is EXPECTED to be called in between a fork() and exec()
+   // when no threads are running. if you use this outside that context then
+   // it may not work as intended and may miss some fd's etc.
    dirfd = open("/proc/self/fd", O_RDONLY | O_DIRECTORY);
    if (dirfd < 0) dirfd = open("/dev/fd", O_RDONLY | O_DIRECTORY);
    if (dirfd >= 0)
@@ -1384,6 +1387,11 @@ skip2:
                   if (clo < num_closes) closes[clo] = num;
                   clo++;
                }
+             // in case we somehow don't fill up all of closes in 2nd pass
+             // (this shouldn't happen as no threads are running and we
+             // do nothing to modify the fd set between 2st and 2nd pass).
+             // set rest num_closes to clo so we don't close invalid values
+             num_closes = clo;
           }
         close(dirfd);
         // now go close all those fd's - some may be invalide like the dir

-- 


Reply via email to