aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2017-01-01 19:05:55 +0100
committerBryn M. Reeves <bmr@redhat.com>2017-02-20 16:53:59 +0000
commit795ef7309af7d49f3f547b231a997730ed6ef626 (patch)
treea30bfb47c5e8ab742483635ddd1d0aced6160c89
parentc29b25f3690d608d34417a4de675942149af3edf (diff)
downloadsos-795ef7309af7d49f3f547b231a997730ed6ef626.tar.gz
[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 <pmoravec@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/sosreport.py3
1 files changed, 2 insertions, 1 deletions
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