diff options
author | Pavel Moravec <pmoravec@redhat.com> | 2017-01-01 19:05:55 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2017-02-20 16:53:59 +0000 |
commit | 795ef7309af7d49f3f547b231a997730ed6ef626 (patch) | |
tree | a30bfb47c5e8ab742483635ddd1d0aced6160c89 | |
parent | c29b25f3690d608d34417a4de675942149af3edf (diff) | |
download | sos-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.py | 3 |
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 |