diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-11-14 14:24:12 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2022-11-21 14:19:17 -0500 |
commit | 1bdbfc963b4d456a0f247a1b82ac2ceec5c391df (patch) | |
tree | 10263f681bf51995df42ff5fda739521d6d6bf18 | |
parent | dcb34e10896612052e91a0474e036c62d6cd27a1 (diff) | |
download | sos-1bdbfc963b4d456a0f247a1b82ac2ceec5c391df.tar.gz |
[utilities] If writing to disk, close file during exception handling
As identified by CodeQL, there was a case where a potential open file we
are/were writing to as part of a command collection would not be closed
if we hit an exception during that execution.
Add explicit closure as part of the exception handling to resolve this.
Related: #3066
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/utilities.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/sos/utilities.py b/sos/utilities.py index 21c815d9..99443bca 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -253,6 +253,8 @@ def sos_get_command_output(command, timeout=TIMEOUT_DEFAULT, stderr=False, truncated = reader.is_full except OSError as e: + if to_file: + _output.close() if e.errno == errno.ENOENT: return {'status': 127, 'output': "", 'truncated': ''} else: |