aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-12-18 19:01:04 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-12-18 19:01:04 +0000
commita20b1c0440560d389b68b9ff2feeb6e94b8248e1 (patch)
tree220036e035ebb29c55369eca5d722389cac9bffe
parentb3d4b9ffc54352b95702babd2f489f8a3f906e2d (diff)
downloadsos-a20b1c0440560d389b68b9ff2feeb6e94b8248e1.tar.gz
Make add_file() more robust
The TarFileArchive with SELinux does not pass the full test archive_tests suite. Catch an uncaught exception when stat'ing a non-existent path and do not allow empty paths in add_parent().
-rw-r--r--sos/archive.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/sos/archive.py b/sos/archive.py
index 74f932c8..4a4d1aeb 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -93,6 +93,8 @@ class TarFileArchive(Archive):
def add_parent(self, path):
path = os.path.split(path)[0]
+ if path == '':
+ return
self.add_file(path)
def add_file(self, src, dest=None):
@@ -130,16 +132,20 @@ class TarFileArchive(Archive):
context = self.get_selinux_context(src)
if context:
tar_info.pax_headers['RHT.security.selinux'] = context
-
- fstat = os.stat(src)
- if os.path.isdir(src) and not (fstat.st_mode & 000200):
- # directories not writable by their owner are a world of pain
- # in tar archives. Do not allow them (see Issue #85).
- mode = fstat.st_mode | 000200
- else:
+ try:
+ fstat = os.stat(src)
+ if os.path.isdir(src) and not (fstat.st_mode & 000200):
+ # directories not writable by their owner are a world of pain
+ # in tar archives. Do not allow them (see Issue #85).
+ mode = fstat.st_mode | 000200
+ else:
+ mode = None
+ self.set_tar_info_from_stat(tar_info,fstat, mode)
+ self.tarfile.addfile(tar_info, fileobj)
+ except Exception as e:
+ raise e
+ finally:
mode = None
- self.set_tar_info_from_stat(tar_info,fstat, mode)
- self.tarfile.addfile(tar_info, fileobj)
def add_string(self, content, dest):
fstat = None