apport-cli crashes if a hook provides a python list which is a directory w/o files

Bug #1596713 reported by Brian Murray
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apport (Ubuntu)
Fix Released
Medium
Martin Pitt

Bug Description

I was reviewing an apport hook for somebody and noticed that apport-cli would crash when you try to save a report (option K) if the apport hook does something odd. As an example:

1) mkdir -p /tmp/directory1/directory2
2) modify an apport package hook to contain the following:
   contents = os.listdir('/tmp/directory1')
   report['DirContents'] = contents
3) run apport-cli ubuntu-release-upgrader (package hook I modified)
4) observe the following crash

Traceback (most recent call last):
  File "/usr/bin/apport-cli", line 370, in <module>
    if not app.run_argv():
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 645, in run_argv
    self.run_symptom()
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 636, in run_symptom
    self.run_report_bug(script)
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 489, in run_report_bug
    response = self.ui_present_report_details(allowed_to_report)
  File "/usr/bin/apport-cli", line 220, in ui_present_report_details
    self.report.write(f)
  File "/usr/lib/python3/dist-packages/problem_report.py", line 448, in write
    f = open(v[0], 'rb') # file name
FileNotFoundError: [Errno 2] No such file or directory: 'directory2'

If DirContents is a folder that contains at least one file we see the following error raised instead.

TypeError: value for key DirContents must be a string, CompressedValue, or a file reference

Tags: xenial
tags: added: xenial
Changed in apport (Ubuntu):
importance: Undecided → Medium
Changed in apport (Ubuntu):
assignee: nobody → Martin Pitt (pitti)
Revision history for this message
Martin Pitt (pitti) wrote :

It is actually legal for a Report value to be a tuple -- the intention is that this is a "file reference", and we make use of that in several places to avoid needless copies in RAM. For example in data/apport:

        info['CoreDump'] = (sys.stdin, True, core_size_limit, True)

or in data/kernel_crashdump:

   pr['VmCoreLog'] = (os.fdopen(log_fd, 'rb'),)

So the problem is that __setitem__() also (erroneously) accepts lists, it does not verify that it is actually a tuple:

        if not (isinstance(v, CompressedValue) or hasattr(v, 'isalnum') or
                (hasattr(v, '__getitem__') and (
                    len(v) == 1 or (len(v) >= 2 and v[1] in (True, False))) and
                    (hasattr(v[0], 'isalnum') or hasattr(v[0], 'read')))):
            raise TypeError("value for key %s must be a string, CompressedValue, or a file reference" % k)

It already does check the length and types of the arguments, though.

Revision history for this message
Martin Pitt (pitti) wrote :

Fixed in http://bazaar.launchpad.net/~apport-hackers/apport/trunk/revision/3089. This will now raise the intended TypeError right when trying to assign a list value.

Changed in apport (Ubuntu):
status: New → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apport - 2.20.3-0ubuntu1

---------------
apport (2.20.3-0ubuntu1) yakkety; urgency=medium

  [ Hans Joachim Desserud ]
  * Fix typo (cehcking -> checking) (LP: #1603463).

  [ Martin Pitt ]
  * New upstream release:
    - problem_report.py: Fail with proper exception when trying to assign a
      list to a report key, or when trying to assing a tuple with more than 4
      entries. (LP: #1596713)
    - test_backend_apt_dpkg.py: Install GPG key for ddebs.ubuntu.com to avoid
      apt authentication errors.
  * Bump Standards-Version to 3.9.8 (no changes necessary).

 -- Martin Pitt <email address hidden> Thu, 28 Jul 2016 14:10:46 +0200

Changed in apport (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.