Ubuntu

apport crashed with error in report.py in anonymize(): nothing to repeat - if GECOS field contains regular expression metacharacters

Reported by Walter Garcia-Fontes on 2012-04-18
52
This bug affects 7 people
Affects Status Importance Assigned to Milestone
apport (Ubuntu)
High
Martin Pitt

Bug Description

TEST CASE:
1. Create a new user or change the gecos field of an existing user and set a phone number starting with a '+' in the Gecos field
2. File a new bug report with apport:
  $ ubuntu-bug apport

RESULT
This crash
Traceback (most recent call last):
  File "/usr/share/apport/apport-gtk", line 590, in <module>
    app.run_argv()
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 656, in run_argv
    return self.run_report_bug()
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 458, in run_report_bug
    self.collect_info(symptom_script)
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 1060, in collect_info
    anonymize_thread.exc_raise()
  File "/usr/lib/python3/dist-packages/apport/REThread.py", line 63, in exc_raise
    raise self._exception[1].with_traceback(self._exception[2])
  File "/usr/lib/python3/dist-packages/apport/REThread.py", line 33, in run
    self._retval = self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python3/dist-packages/apport/report.py", line 1395, in anonymize
    replacements.append((re.compile('\\b%s\\b' % s), 'User Name'))
  File "/usr/lib/python3.3/re.py", line 214, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.3/re.py", line 281, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.3/sre_compile.py", line 494, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.3/sre_parse.py", line 735, in parse
    p = _parse_sub(source, pattern, 0)
  File "/usr/lib/python3.3/sre_parse.py", line 348, in _parse_sub
    itemsappend(_parse(source, state))
  File "/usr/lib/python3.3/sre_parse.py", line 557, in _parse
    raise error("nothing to repeat")
sre_constants.error: nothing to repeat

ORIGINAL REPORT
I'm getting this bug, actually in just one system and one user, I don't get it for instance in the "guest" account. I don't get it either if i run the apport comment with "sudo".

ProblemType: Crash
DistroRelease: Ubuntu 12.04
Package: apport 2.0.1-0ubuntu4
ProcVersionSignature: Ubuntu 3.2.0-23.36-generic 3.2.14
Uname: Linux 3.2.0-23-generic x86_64
NonfreeKernelModules: nvidia
ApportLog:

ApportVersion: 2.0.1-0ubuntu4
Architecture: amd64
CrashCounter: 1
Date: Wed Apr 18 18:12:40 2012
ExecutablePath: /usr/bin/apport-cli
InstallationMedia: Ubuntu 10.10 "Maverick Meerkat" - Release amd64 (20101007)
InterpreterPath: /usr/bin/python2.7
PackageArchitecture: all
ProcCmdline: /usr/bin/python /usr/bin/apport-cli -f -p cheese --save cheese.txt
ProcCwd: /home/wgarcia
PythonArgs: ['/usr/bin/apport-cli', '-f', '-p', 'cheese', '--save', 'cheese.txt']
SourcePackage: apport
Title: apport-cli crashed with error in _compile(): nothing to repeat
UpgradeStatus: Upgraded to precise on 2012-03-05 (44 days ago)
UserGroups: adm admin audio cdrom dialout lp lpadmin plugdev sambashare video

Related branches

visibility: private → public
tags: removed: need-duplicate-check
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in apport (Ubuntu):
status: New → Confirmed
Changed in apport (Ubuntu):
importance: Undecided → Medium

I'm stil having this problem in one particular system, only with my normal user (not with the guest user or running apport with "sudo"). The user name is not strange, and I use it in a lot of other systems and apport does not produce this error.

I found a workaround by commenting out lines 1296 and 1297 of /usr/lib/python2.7/dist-packages/apport/report.py. This seems to be some sort of problem with a regular expression in this line, similar to what is being discussed here:

http://stackoverflow.com/questions/3675144/regex-error-nothing-to-repeat

But what I don't understand is why I only get this error in one particular system.

I'm still having this error on the same system. I have update from 11.10 to 12.04 and now to 12.10 and the error persists. Whenever I use apport I get this error (nothing to repeat). I don't get it if I run apport with "sudo", nor in the guest account. What configuration files of apport may be causing this?

There are several workarounds suggested:

    Commenting out lines 1296 and 1297 of /usr/lib/python2.7/dist-packages/apport/report.py.
    Changing user name or creating a new user account.

no longer affects: apport
Claes Comly (ccomly) wrote :

12.10 unity-compiz

same problem, different python, tried commenting out 1296 and 1297 they look the same in python3.

                    # avoid ':' in ELF paths, we use that as separator
                    stack.append(offset.replace(':', '..'))

since one is already commented im guessing these are not the correct lines to comment out. Would appreciate a working workaround. thanks.

Traceback (most recent call last):
  File "/usr/share/apport/apport-gtk", line 588, in <module>
    app.run_argv()
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 637, in run_argv
    return self.run_report_bug()
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 439, in run_report_bug
    self.collect_info(symptom_script)
  File "/usr/lib/python3/dist-packages/apport/ui.py", line 1041, in collect_info
    anonymize_thread.exc_raise()
  File "/usr/lib/python3/dist-packages/apport/REThread.py", line 64, in exc_raise
    raise self._exception[1].with_traceback(self._exception[2])
  File "/usr/lib/python3/dist-packages/apport/REThread.py", line 34, in run
    self._retval = self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python3/dist-packages/apport/report.py", line 1340, in anonymize
    replacements.append((re.compile('\\b%s\\b' % s), 'User Name'))
  File "/usr/lib/python3.2/re.py", line 214, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.2/re.py", line 263, in _compile
    return _compile_typed(type(pattern), pattern, flags)
  File "/usr/lib/python3.2/functools.py", line 184, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/lib/python3.2/re.py", line 275, in _compile_typed
    return sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.2/sre_compile.py", line 491, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.2/sre_parse.py", line 692, in parse
    p = _parse_sub(source, pattern, 0)
  File "/usr/lib/python3.2/sre_parse.py", line 315, in _parse_sub
    itemsappend(_parse(source, state))
  File "/usr/lib/python3.2/sre_parse.py", line 520, in _parse
    raise error("nothing to repeat")
sre_constants.error: nothing to repeat

I'm still having this issue in the same system now updated to raring. My workaround is to comment out the "if" statement at the line number mentioned at the end of the traceback reported. In my last case I get

File "/usr/lib/python3.3/sre_parse.py", line 557, in _parse
    raise error("nothing to repeat")
sre_constants.error: nothing to repeat

as the last three lines before apport stopped. So I edited "/usr/lib/python3.3/sre_parse.py" and commented out lines 556 and 557, which now look as follows

# if not item or (_len(item) == 1 and item[0][0] == AT):
# raise error("nothing to repeat")

Still curious to know what causes this issue, I've tried purging apport, crash reports, but to no avail, I always get the above error as soon as apport or python get some update.

Changed in apport (Ubuntu):
importance: Medium → High
status: Confirmed → Triaged
summary: - apport-cli crashed with error in _compile(): nothing to repeat
+ apport-cli crashed with error in _compile(): nothing to repeat - Escape
+ GECOS field in apport.report.anonymize()

This is because the GECOS field contains a string starting with a '+' (for example a phone number) and the string that is replaced in the regex to anonymize user name is not escaped.

The code below is an excerpt of apport.report.anonymize(self) that reproduces the issue:
==========
import re
p='My User-Name,12.123,+123456789,+123456789,'
replacements=[]
for s in p.split(','):
    s = s.strip()
    if len(s) > 2:
        print(s)
        replacements.append((re.compile('\\b%s\\b' % s), 'User Name'))
==========

The GECOS field should be escaped as it contains general information and forbidden characters in regexp.

description: updated
tags: added: rls-r-incoming
description: updated
description: updated
summary: - apport-cli crashed with error in _compile(): nothing to repeat - Escape
- GECOS field in apport.report.anonymize()
+ apport crashed with error in report.py in anonymize(): nothing to repeat
+ - if GECOS field contains regular expression metacharacters
Martin Pitt (pitti) wrote :

Fixed in trunk r2622

Changed in apport (Ubuntu):
status: Triaged → Fix Committed
assignee: nobody → Martin Pitt (pitti)
Launchpad Janitor (janitor) wrote :

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

---------------
apport (2.10-0ubuntu1) saucy; urgency=low

  [ Martin Pitt ]
  * New upstream release. Changes since our previous snapshot:
    - Support retracing foreign powerpc reports, thanks Steve Langasek.
    - apport/report.py: Generate a crash signature for suspend/resume failures.
    - hookutils.py: Add attach_upstart_logs(), thanks Steve Langasek.
    - hookutils.py, in_session_of_problem(): Port from ConsoleKit to logind.
    - apport/report.py: Handle the case where the user has been removed from
      the system, but one of its still-running binaries crashes (LP: #1163453).
    - Fix anonymization of user/GECOS fields with regexp control characters
      like '+'. (LP: #985049)
    - Run tests under LC_CTYPE=C and unset LANG as well, to discover
      assumptions about UTF-8 locales. Fix the two failing tests.
    - Fix UnicodeDecodeError when apport encounters non-ASCII environment
      variables. (LP: #1172638)
  * debian/control: Update Vcs-* for saucy branch.
  * data/general-hooks/cloud_archive.py: Fix PEP-8 error.

  [ Steve Langasek ]
  * data/general-hooks/ubuntu.py: Call attach_upstart_logs(), to attach the
    logs for any upstart user jobs shipped by the binary package.
 -- Martin Pitt <email address hidden> Tue, 30 Apr 2013 14:49:42 -0700

Changed in apport (Ubuntu):
status: Fix Committed → Fix Released
Peter Nagy (antronin) wrote :

This is still not fixed in Raring 13.04. I just linked a bugreport created some minutes ago on my fully up-to-date 13.04. See #1220267

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

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