Subject: bug#15759: regression in grep 2.15 with PCRE searches

From: Dave Reisner <[email-masked]>
Date: Wed, 30 Oct 2013 13:23:10 -0400

Hi,

A user reported a regression in grep 2.15 which is easily reproducible
as ``grep -P foo /bin/mount''. The root cause is that pcre_exec is
returning PCRE_ERROR_BADUTF8 when the current locale supports UTF-8.
This is unhandled by grep and causes it to call abort().

I bisected the breakage to commit 67436786c110bb which essentially
introduces UTF-8 validation for all searched data. In a large number of
file hierarchies, one may easily hit this via a recursive search.

I crafted the following inline diff which fixes the problem. While I'm
not sure of its correctness, it at least describes one possible fix.

  diff --git a/src/pcresearch.c b/src/pcresearch.c
  index ad5999d..ce55ab3 100644
  --- a/src/pcresearch.c
  +++ b/src/pcresearch.c
  @@ -176,6 +176,9 @@ Pexecute (char const *buf, size_t size, size_t *match_size,
         switch (e)
           {
           case PCRE_ERROR_NOMATCH:
  +#ifdef HAVE_LANGINFO_CODESET
  +        case PCRE_ERROR_BADUTF8:
  +#endif
             return -1;

           case PCRE_ERROR_NOMEMORY:

Cheers,
Dave