Invalid regular expression crashes log output

Bug #251352 reported by William Fagan
6
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Low
Martin Pool

Bug Description

When doing a log command with an invalid regular expression passed in bzr crashes.

For example...

bzr log --message=*

outputs...

---------------------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 834, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 790, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 492, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 800, in ignore_pipe
    result = func(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/builtins.py", line 1765, in run
    limit=limit)
  File "/usr/lib/python2.5/site-packages/bzrlib/log.py", line 189, in show_log
    start_revision, end_revision, search, limit)
  File "/usr/lib/python2.5/site-packages/bzrlib/log.py", line 306, in _show_log
    if not searchRE.search(rev.message):
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_regex.py", line 69, in __getattr__
    self._compile_and_collapse()
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_regex.py", line 55, in _compile_and_collapse
    **self._regex_kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_regex.py", line 61, in _real_re_compile
    return _real_re_compile(*args, **kwargs)
  File "/usr/lib/python2.5/re.py", line 188, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python2.5/re.py", line 241, in _compile
    raise error, v # invalid expression
error: nothing to repeat

bzr 1.3.1 on python 2.5.2.final.0 (linux2)
arguments: ['/usr/bin/bzr', 'log', '--message=*']
encoding: 'UTF-8', fsenc: 'UTF-8', lang: 'en_US.UTF-8'
plugins:
  launchpad /usr/lib/python2.5/site-packages/bzrlib/plugins/launchpad [unknown]
  xmloutput /home/will/.bazaar/plugins/xmloutput [0.5.0]
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.
---------------------------------------------------------------------------------------------------

I think bazaar should handle this better. Possibly just outputting nothing.

Tags: log

Related branches

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

I agree. I think we should print some error message though (just a one-liner) to avoid user confusion.

Changed in bzr:
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Anne Mohsen (anne-mohsen) wrote :

I propose to catch the exception and print an error message, in the attached patch

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 251352] Re: Invalid regular expression crashes log output

On Tue, 2009-01-27 at 22:05 +0000, Anne Mohsen wrote:
> I propose to catch the exception and print an error message, in the
> attached patch

This would work, but on the down side it will add a try:except to the
inner loop.

Perhaps compiling the expression first would work? It should generate
the error at compilation time, and then that could be could and emitted,
and would be outside the loop.

-Rob

Revision history for this message
Anne Mohsen (anne-mohsen) wrote :

Now the try/except is outside of the loop.
There is already a re.compile call:
searchRE = re.compile(search, re.IGNORECASE)
But searchRE is a LazyRegex object, and is really compiled only at the first call of the search method.
searchRE.search("") is a way to force it to be compiled outside of the loop, without explicitly importing lazy_regex.

Revision history for this message
GuilhemBichot (guilhem-bichot) wrote :

I hit this. Any news?

tags: added: log
Revision history for this message
Martin Pool (mbp) wrote :

I'll add a test and put it up for review.

Changed in bzr:
assignee: nobody → mbp
status: Triaged → In Progress
Revision history for this message
Martin Pool (mbp) wrote :

It seems to me while we're here we should check for other things that might need to raise a clean message on bad REs.

Revision history for this message
Martin Pool (mbp) wrote : [merge][#251352] better messages for illegal 'log -m' arguments

Based on Anne Mohsen's patch in
<https://bugs.edge.launchpad.net/bzr/+bug/251352> this gives a nicer
message when the user gives an illegal regexp. (Thanks, Anne.) It
also separates out a function re_compile_checked that we should use
whenever compiling a user-supplied regexp because the python default
error is not very helpful.

I haven't added this into the ignore code (yet) because it's not
directly applicable and that code already makes some effort not to
compile them one by one for the sake of speed.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> Based on Anne Mohsen's patch in
> <https://bugs.edge.launchpad.net/bzr/+bug/251352> this gives a nicer
> message when the user gives an illegal regexp. (Thanks, Anne.) It
> also separates out a function re_compile_checked that we should use
> whenever compiling a user-supplied regexp because the python default
> error is not very helpful.
>
> I haven't added this into the ignore code (yet) because it's not
> directly applicable and that code already makes some effort not to
> compile them one by one for the sake of speed.
>
>

BB:approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknIPukACgkQJdeBCYSNAAMtNgCg0gUpkv0q4DFaWeSo+7a2+wDj
KGsAoIWFQjiwsLAPV7JVtsAumBpbYJBF
=1QXc
-----END PGP SIGNATURE-----

Revision history for this message
Martin Pool (mbp) wrote :

Will be in 1.14rc1

Changed in bzr:
status: In Progress → Fix Released
Vincent Ladeuil (vila)
Changed in bzr:
milestone: none → 1.14rc1
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.