=== modified file 'DistUpgrade/DistUpgradeApport.py' --- DistUpgrade/DistUpgradeApport.py 2012-05-16 21:05:42 +0000 +++ DistUpgrade/DistUpgradeApport.py 2012-05-30 21:27:08 +0000 @@ -6,6 +6,28 @@ import gettext import errno +APPORT_WHITELIST = [ + "apt.log", + "apt-term.log", + "history.log", + "lspci.txt", + "main.log", + "term.log", + "screenlog.0", + "xorg_fixup.log", + ] + + +def _apport_append_logfiles(report, logdir="/var/log/dist-upgrade/"): + for fname in os.listdir(logdir): + if not fname in APPORT_WHITELIST: + continue + f = os.path.join(logdir, fname) + if not os.path.isfile(f) or os.path.getsize(f) == 0: + continue + report[f.replace(".","").replace("-","")] = (open(f), ) + + def apport_crash(type, value, tb): logging.debug("running apport_crash()") try: @@ -22,11 +44,7 @@ report = Report() report.setdefault('Tags', 'dist-upgrade') report['Tags'] += ' dist-upgrade' - for fname in os.listdir("/var/log/dist-upgrade/"): - f = os.path.join("/var/log/dist-upgrade",fname) - if not os.path.isfile(f) or os.path.getsize(f) == 0: - continue - report[f.replace(".","").replace("-","")] = (open(f), ) + _apport_append_logfiles(report) report.add_to_existing('/var/crash/_usr_bin_update-manager.0.crash') return True @@ -48,8 +66,11 @@ return False if os.path.exists(s): + args = [s, "-p", pkg] + for fname in APPORT_WHITELIST: + args.extend(["-l", os.path.join(LOGDIR, fname)]) try: - p = subprocess.Popen([s,"-p",pkg,"-l",LOGDIR], stdin=subprocess.PIPE) + p = subprocess.Popen(args, stdin=subprocess.PIPE) p.stdin.write("ErrorMessage: %s\n" % errormsg) p.stdin.close() #p.wait() === added file 'tests/test_apport_crash.py' --- tests/test_apport_crash.py 1970-01-01 00:00:00 +0000 +++ tests/test_apport_crash.py 2012-05-29 16:04:23 +0000 @@ -0,0 +1,26 @@ +#!/usr/bin/python + +import os +import sys +import tempfile +import unittest + +sys.path.insert(0, "..") +from DistUpgrade.DistUpgradeApport import _apport_append_logfiles + +class TestApportInformationLeak(unittest.TestCase): + + def test_no_information_apport_leaking(self): + tmpdir = tempfile.mkdtemp() + report = {} + for name in ["apt.log", "system_state.tar.gz", "bar", "main.log"]: + with open(os.path.join(tmpdir, name), "w") as f: + f.write("some-data") + _apport_append_logfiles(report, tmpdir) + self.assertEqual(sorted([f[0].name for f in report.values()]), + sorted([os.path.join(tmpdir, "main.log"), + os.path.join(tmpdir, "apt.log")])) + + +if __name__ == "__main__": + unittest.main()