rcolebaugh / rpms / bash

Forked from rpms/bash 2 years ago
Clone

Blame SOURCES/bash-4.2-missing_closes.patch

07a490
There are missing calls of close() leading to resource leak (fd leak).
07a490
Simple reproducer:
07a490
. /
07a490
and /proc/$$/fd contain one open fd for each above call
07a490

07a490
Signed-off-by: Roman Rakus <rrakus@redhat.com>
07a490
---
07a490
 builtins/evalfile.c | 3 +++
07a490
 1 file changed, 3 insertions(+)
07a490

07a490
diff --git a/builtins/evalfile.c b/builtins/evalfile.c
07a490
index 60f89d1..d30bd96 100644
07a490
--- a/builtins/evalfile.c
07a490
+++ b/builtins/evalfile.c
07a490
@@ -133,11 +133,13 @@ file_error_and_exit:
07a490
   if (S_ISDIR (finfo.st_mode))
07a490
     {
07a490
       (*errfunc) (_("%s: is a directory"), filename);
07a490
+      close(fd);
07a490
       return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
07a490
     }
07a490
   else if ((flags & FEVAL_REGFILE) && S_ISREG (finfo.st_mode) == 0)
07a490
     {
07a490
       (*errfunc) (_("%s: not a regular file"), filename);
07a490
+      close(fd);
07a490
       return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
07a490
     }
07a490
 
07a490
@@ -146,6 +148,7 @@ file_error_and_exit:
07a490
   if (file_size != finfo.st_size || file_size + 1 < file_size)
07a490
     {
07a490
       (*errfunc) (_("%s: file is too large"), filename);
07a490
+      close(fd);
07a490
       return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
07a490
     }      
07a490
 
07a490
-- 
07a490
1.7.11.7
07a490