From 795ef7309af7d49f3f547b231a997730ed6ef626 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Sun, 1 Jan 2017 19:05:55 +0100 Subject: [general] close unused file descriptors of temp.files tempfile.mkstemp call opens a new FD that is redundantly left intact until sosreport shutdown. Let close it (added minor fix to avoid TOCTOU race - bmr). Signed-off-by: Pavel Moravec Signed-off-by: Bryn M. Reeves --- sos/sosreport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sos/sosreport.py b/sos/sosreport.py index 62942e82..dd3a60c7 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -83,7 +83,8 @@ class TempFileUtil(object): def new(self): fd, fname = tempfile.mkstemp(dir=self.tmp_dir) - fobj = open(fname, 'w') + # avoid TOCTOU race by using os.fdopen() + fobj = os.fdopen(fd) self.files.append((fname, fobj)) return fobj -- cgit