Subject: bug#19420: intermittent segfault using grep -P

From: Norihiro Tanaka <[email-masked]>
Date: Tue, 23 Dec 2014 00:55:02 +0900

It could reproduce as following in Fedora21, RHEL 6.5.

$ cd pcre-8.36
$ CFLAGS=-g ./configure --enable-utf --enable-unicode-properties
$ make
# make install

grep-2.21
$ ./configure
$ make
# make install

By the way, if we enabled to optimize or recompile pcre with --enable-jit
option, it did not reproduced.

However, I see that it is an issue in PRE side.  It reproduces with
following test case without grep frontend.

==
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pcre.h>

enum { LEN = 15000 };
enum { NSUB = 300 };

int
main ()
{
  char *text = malloc ((LEN + 1) * sizeof *text);
  memset (text, '0', LEN);
  text[LEN] = '\0';
  char const *re = "0(?:(?!foo).)+";
  char const *ep;
  int eo;

  pcre *cre = pcre_compile (re, 0, &ep, &eo, NULL);
  if (!cre)
    exit (EXIT_FAILURE);

  int sub[NSUB];
  pcre_exec (cre, NULL, text, strlen (text), 0, 0, sub, NSUB);

  exit (EXIT_SUCCESS);
}
==