{"thread":{"id":"47296","subject":"[PATCH 1/2] test-lib: add LIBPCRE1 & LIBPCRE2 prerequisites","startedAt":"2017-11-22T13:36:47Z","lastAt":"2017-11-23T14:17:20Z","messageCount":9,"participants":["Ævar Arnfjörð Bjarmason","Eric Sunshine","Jonathan Nieder","Simon Ruderich"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"333273","messageId":"20171122133630.18931-1-avarab@gmail.com","threadId":"47296","inReplyTo":null,"subject":"[PATCH 1/2] test-lib: add LIBPCRE1 & LIBPCRE2 prerequisites","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-11-22T13:36:29Z","receivedAt":"2017-11-22T13:36:47Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add LIBPCRE1 and LIBPCRE2 prerequisites which are true when git is\ncompiled with USE_LIBPCRE1=YesPlease or USE_LIBPCRE2=YesPlease,\nrespectively.\n\nThe syntax of PCRE1 and PCRE2 isn't the same in all cases (see\npcresyntax(3) and pcre2syntax(3)). If test are added that test for\nthose they'll need to be guarded by these new prerequisites.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README      | 12 ++++++++++++\n t/test-lib.sh |  2 ++\n 2 files changed, 14 insertions(+)\n\ndiff --git a/t/README b/t/README\nindex 4b079e4494..599cd9808c 100644\n--- a/t/README\n+++ b/t/README\n@@ -808,6 +808,18 @@ use these, and \"test_set_prereq\" for how to define your own.\n    Git was compiled with support for PCRE. Wrap any tests\n    that use git-grep --perl-regexp or git-grep -P in these.\n \n+ - LIBPCRE1\n+\n+   Git was compiled with PCRE v1 support via\n+   USE_LIBPCRE1=YesPlease. Wrap any PCRE using tests that for some\n+   reason need v1 of the PCRE library instead of v2 in these.\n+\n+ - LIBPCRE2\n+\n+   Git was compiled with PCRE v2 support via\n+   USE_LIBPCRE2=YesPlease. Wrap any PCRE using tests that for some\n+   reason need v2 of the PCRE library instead of v1 in these.\n+\n  - CASE_INSENSITIVE_FS\n \n    Test is run on a case insensitive file system.\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 116bd6a70c..e7065df2bb 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1028,6 +1028,8 @@ test -z \"$NO_PERL\" && test_set_prereq PERL\n test -z \"$NO_PTHREADS\" && test_set_prereq PTHREADS\n test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n test -n \"$USE_LIBPCRE1$USE_LIBPCRE2\" && test_set_prereq PCRE\n+test -n \"$USE_LIBPCRE1\" && test_set_prereq LIBPCRE1\n+test -n \"$USE_LIBPCRE2\" && test_set_prereq LIBPCRE2\n test -z \"$NO_GETTEXT\" && test_set_prereq GETTEXT\n \n # Can we rely on git's output in the C locale?\n-- \n2.15.0.403.gc27cc4dac6\n\n"},{"id":"333274","messageId":"20171122133630.18931-2-avarab@gmail.com","threadId":"47296","inReplyTo":"20171122133630.18931-1-avarab@gmail.com","subject":"[PATCH 2/2] grep: fix segfault under -P + PCRE2 + (*NO_JIT)","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-11-22T13:36:30Z","receivedAt":"2017-11-22T13:36:54Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Fix a bug in the compilation of PCRE2 patterns under JIT (the most\ncommon runtime configuration), any pattern with a (*NO_JIT) verb would\nsegfault. This bug dates back to my 94da9193a6 (\"grep: add support for\nPCRE v2\", 2017-06-01):\n\n    $ git grep -P '(*NO_JIT)hi.*there'\n    Segmentation fault\n\nAs explained ad more length in the comment being added here it isn't\nsufficient to just check pcre2_config() to see whether the JIT should\nbe used, pcre2_pattern_info() also has to be asked.\n\nThis is something I discovered myself when fiddling around with PCRE2\nverbs in patterns passed to git. I don't expect that any user of git\nhas encountered this given the obscurity of passing PCRE2 verbs\nthrough to the library, along with the relative obscurity of (*NO_JIT)\nitself.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n grep.c          | 25 +++++++++++++++++++++++++\n t/t7810-grep.sh |  6 ++++++\n 2 files changed, 31 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex d0b9b6cdfa..f3139e867c 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -477,6 +477,8 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt\n \tint options = PCRE2_MULTILINE;\n \tconst uint8_t *character_tables = NULL;\n \tint jitret;\n+\tint patinforet;\n+\tsize_t jitsizearg;\n \n \tassert(opt->pcre2);\n \n@@ -511,6 +513,29 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt\n \t\tjitret = pcre2_jit_compile(p->pcre2_pattern, PCRE2_JIT_COMPLETE);\n \t\tif (jitret)\n \t\t\tdie(\"Couldn't JIT the PCRE2 pattern '%s', got '%d'\\n\", p->pattern, jitret);\n+\n+\t\t/*\n+\t\t * The pcre2_config(PCRE2_CONFIG_JIT, ...) call just\n+\t\t * tells us whether the library itself supports JIT,\n+\t\t * but to see whether we're going to be actually using\n+\t\t * JIT we need to extract PCRE2_INFO_JITSIZE from the\n+\t\t * pattern *after* we do pcre2_jit_compile() above.\n+\t\t *\n+\t\t * This is because if the pattern contains the\n+\t\t * (*NO_JIT) verb (see pcre2syntax(3))\n+\t\t * pcre2_jit_compile() will exit early with 0. If we\n+\t\t * then proceed to call pcre2_jit_match() further down\n+\t\t * the line instead of pcre2_match() we'll segfault.\n+\t\t */\n+\t\tpatinforet = pcre2_pattern_info(p->pcre2_pattern, PCRE2_INFO_JITSIZE, &jitsizearg);\n+\t\tif (patinforet)\n+\t\t\tdie(\"BUG: The patinforet variable should be 0 after the pcre2_pattern_info() call, not %d\",\n+\t\t\t    patinforet);\n+\t\tif (jitsizearg == 0) {\n+\t\t\tp->pcre2_jit_on = 0;\n+\t\t\treturn;\n+\t\t}\n+\n \t\tp->pcre2_jit_stack = pcre2_jit_stack_create(1, 1024 * 1024, NULL);\n \t\tif (!p->pcre2_jit_stack)\n \t\t\tdie(\"Couldn't allocate PCRE2 JIT stack\");\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 2a6679c2f5..c8ff50cc30 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -1110,6 +1110,12 @@ test_expect_success PCRE 'grep -P pattern' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success LIBPCRE2 \"grep -P with (*NO_JIT) doesn't error out\" '\n+\tgit grep -P \"(*NO_JIT)\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+\n+'\n+\n test_expect_success !PCRE 'grep -P pattern errors without PCRE' '\n \ttest_must_fail git grep -P \"foo.*bar\"\n '\n-- \n2.15.0.403.gc27cc4dac6\n\n"},{"id":"333311","messageId":"CAPig+cS_R5wcJQNavGSgNQXtbXNbDsTDhj8cbSZ5BBxRqU8yRQ@mail.gmail.com","threadId":"47296","inReplyTo":"20171122133630.18931-2-avarab@gmail.com","subject":"Re: [PATCH 2/2] grep: fix segfault under -P + PCRE2 + (*NO_JIT)","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2017-11-22T18:18:38Z","receivedAt":"2017-11-22T18:18:44Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Nov 22, 2017 at 8:36 AM, Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> Fix a bug in the compilation of PCRE2 patterns under JIT (the most\n> common runtime configuration), any pattern with a (*NO_JIT) verb would\n> segfault. This bug dates back to my 94da9193a6 (\"grep: add support for\n> PCRE v2\", 2017-06-01):\n>\n>     $ git grep -P '(*NO_JIT)hi.*there'\n>     Segmentation fault\n>\n> As explained ad more length in the comment being added here it isn't\n\ns/ad/at/\ns/here/here,/\n\n> sufficient to just check pcre2_config() to see whether the JIT should\n> be used, pcre2_pattern_info() also has to be asked.\n>\n> This is something I discovered myself when fiddling around with PCRE2\n> verbs in patterns passed to git. I don't expect that any user of git\n> has encountered this given the obscurity of passing PCRE2 verbs\n> through to the library, along with the relative obscurity of (*NO_JIT)\n> itself.\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"333320","messageId":"20171122202259.GC11671@aiede.mtv.corp.google.com","threadId":"47296","inReplyTo":"20171122133630.18931-1-avarab@gmail.com","subject":"Re: [PATCH 1/2] test-lib: add LIBPCRE1 & LIBPCRE2 prerequisites","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2017-11-22T20:22:59Z","receivedAt":"2017-11-22T20:23:07Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nÆvar Arnfjörð Bjarmason wrote:\n\n> Add LIBPCRE1 and LIBPCRE2 prerequisites which are true when git is\n> compiled with USE_LIBPCRE1=YesPlease or USE_LIBPCRE2=YesPlease,\n> respectively.\n>\n> The syntax of PCRE1 and PCRE2 isn't the same in all cases (see\n> pcresyntax(3) and pcre2syntax(3)). If test are added that test for\n> those they'll need to be guarded by these new prerequisites.\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>  t/README      | 12 ++++++++++++\n>  t/test-lib.sh |  2 ++\n>  2 files changed, 14 insertions(+)\n> \n> diff --git a/t/README b/t/README\n> index 4b079e4494..599cd9808c 100644\n> --- a/t/README\n> +++ b/t/README\n> @@ -808,6 +808,18 @@ use these, and \"test_set_prereq\" for how to define your own.\n>     Git was compiled with support for PCRE. Wrap any tests\n>     that use git-grep --perl-regexp or git-grep -P in these.\n>  \n> + - LIBPCRE1\n> +\n> +   Git was compiled with PCRE v1 support via\n> +   USE_LIBPCRE1=YesPlease. Wrap any PCRE using tests that for some\n> +   reason need v1 of the PCRE library instead of v2 in these.\n\nAre there plans to use the LIBPCRE1 prereq?  It might be simpler to\nonly have LIBPCRE2, and LIBPCRE1 can still be expressed as\n\n\tPCRE,!LIBPCRE2\n\nwhich I think is clearer about the intent.\n\nThanks,\nJonathan\n"},{"id":"333377","messageId":"20171123091040.GA8095@ruderich.org","threadId":"47296","inReplyTo":"20171122133630.18931-2-avarab@gmail.com","subject":"Re: [PATCH 2/2] grep: fix segfault under -P + PCRE2 + (*NO_JIT)","fromName":"Simon Ruderich","fromEmail":"simon@ruderich.org","sentAt":"2017-11-23T09:10:40Z","receivedAt":"2017-11-23T09:10:55Z","isPatch":true,"sender":{"key":"simon@ruderich.org","avatar":"https://avatars.githubusercontent.com/u/390994?v=4"},"body":"On Wed, Nov 22, 2017 at 01:36:30PM +0000, Ævar Arnfjörð Bjarmason wrote:\n> +\t\t *\n> +\t\t * This is because if the pattern contains the\n> +\t\t * (*NO_JIT) verb (see pcre2syntax(3))\n> +\t\t * pcre2_jit_compile() will exit early with 0. If we\n> +\t\t * then proceed to call pcre2_jit_match() further down\n> +\t\t * the line instead of pcre2_match() we'll segfault.\n> +\t\t */\n> +\t\tpatinforet = pcre2_pattern_info(p->pcre2_pattern, PCRE2_INFO_JITSIZE, &jitsizearg);\n> +\t\tif (patinforet)\n> +\t\t\tdie(\"BUG: The patinforet variable should be 0 after the pcre2_pattern_info() call, not %d\",\n> +\t\t\t    patinforet);\n\nI think BUG() should be used here, and maybe shorten the error\nmessage:\n\n    BUG(\"pcre2_pattern_info() failed: %d\", patinforet);\n\nRegards\nSimon\n-- \n+ privacy is necessary\n+ using gnupg http://gnupg.org\n+ public key id: 0x92FEFDB7E44C32F9\n"},{"id":"333378","messageId":"87d149we9a.fsf@evledraar.booking.com","threadId":"47296","inReplyTo":"20171122202259.GC11671@aiede.mtv.corp.google.com","subject":"Re: [PATCH 1/2] test-lib: add LIBPCRE1 & LIBPCRE2 prerequisites","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-11-23T09:11:45Z","receivedAt":"2017-11-23T09:11:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Nov 22 2017, Jonathan Nieder jotted:\n\n> Hi,\n>\n> Ævar Arnfjörð Bjarmason wrote:\n>\n>> Add LIBPCRE1 and LIBPCRE2 prerequisites which are true when git is\n>> compiled with USE_LIBPCRE1=YesPlease or USE_LIBPCRE2=YesPlease,\n>> respectively.\n>>\n>> The syntax of PCRE1 and PCRE2 isn't the same in all cases (see\n>> pcresyntax(3) and pcre2syntax(3)). If test are added that test for\n>> those they'll need to be guarded by these new prerequisites.\n>>\n>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>> ---\n>>  t/README      | 12 ++++++++++++\n>>  t/test-lib.sh |  2 ++\n>>  2 files changed, 14 insertions(+)\n>>\n>> diff --git a/t/README b/t/README\n>> index 4b079e4494..599cd9808c 100644\n>> --- a/t/README\n>> +++ b/t/README\n>> @@ -808,6 +808,18 @@ use these, and \"test_set_prereq\" for how to define your own.\n>>     Git was compiled with support for PCRE. Wrap any tests\n>>     that use git-grep --perl-regexp or git-grep -P in these.\n>>\n>> + - LIBPCRE1\n>> +\n>> +   Git was compiled with PCRE v1 support via\n>> +   USE_LIBPCRE1=YesPlease. Wrap any PCRE using tests that for some\n>> +   reason need v1 of the PCRE library instead of v2 in these.\n>\n> Are there plans to use the LIBPCRE1 prereq?  It might be simpler to\n> only have LIBPCRE2, and LIBPCRE1 can still be expressed as\n>\n> \tPCRE,!LIBPCRE2\n>\n> which I think is clearer about the intent.\n\nI prefer to keep it as it is. It's more obvious to me to have a 1=1\nmapping between the ${USE,NO}_* variables and the prerequisites, and\nit's future-proof if there's ever a PCRE v3, since tests that use this\nwill mean v1 specifically, not just any non-v2 version (although now v1\nis the only one).\n"},{"id":"333379","messageId":"87bmjtwe2n.fsf@evledraar.booking.com","threadId":"47296","inReplyTo":"CAPig+cS_R5wcJQNavGSgNQXtbXNbDsTDhj8cbSZ5BBxRqU8yRQ@mail.gmail.com","subject":"Re: [PATCH 2/2] grep: fix segfault under -P + PCRE2 + (*NO_JIT)","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-11-23T09:15:44Z","receivedAt":"2017-11-23T09:15:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Nov 22 2017, Eric Sunshine jotted:\n\n> On Wed, Nov 22, 2017 at 8:36 AM, Ævar Arnfjörð Bjarmason\n> <avarab@gmail.com> wrote:\n>> Fix a bug in the compilation of PCRE2 patterns under JIT (the most\n>> common runtime configuration), any pattern with a (*NO_JIT) verb would\n>> segfault. This bug dates back to my 94da9193a6 (\"grep: add support for\n>> PCRE v2\", 2017-06-01):\n>>\n>>     $ git grep -P '(*NO_JIT)hi.*there'\n>>     Segmentation fault\n>>\n>> As explained ad more length in the comment being added here it isn't\n>\n> s/ad/at/\n> s/here/here,/\n\nThanks. I'll let this sit for a bit and submit a v2 soon. There's also\nan upstream fix in pcre2 to prevent the segfault that'll be in future\nversions & I'm going to note in the amended commit message.\n\n>> sufficient to just check pcre2_config() to see whether the JIT should\n>> be used, pcre2_pattern_info() also has to be asked.\n>>\n>> This is something I discovered myself when fiddling around with PCRE2\n>> verbs in patterns passed to git. I don't expect that any user of git\n>> has encountered this given the obscurity of passing PCRE2 verbs\n>> through to the library, along with the relative obscurity of (*NO_JIT)\n>> itself.\n>>\n>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"333382","messageId":"20171123141658.13010-1-avarab@gmail.com","threadId":"47296","inReplyTo":"20171122133630.18931-2-avarab@gmail.com","subject":"[PATCH v2 1/2] test-lib: add LIBPCRE1 & LIBPCRE2 prerequisites","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-11-23T14:16:57Z","receivedAt":"2017-11-23T14:17:18Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add LIBPCRE1 and LIBPCRE2 prerequisites which are true when git is\ncompiled with USE_LIBPCRE1=YesPlease or USE_LIBPCRE2=YesPlease,\nrespectively.\n\nThe syntax of PCRE1 and PCRE2 isn't the same in all cases (see\npcresyntax(3) and pcre2syntax(3)). If test are added that test for\nthose they'll need to be guarded by these new prerequisites.\n\nThe subsequent patch will make use of LIBPCRE2, so LIBPCRE1 isn't\nstrictly needed for now, but let's add it for consistency and so that\nchecking for it doesn't have to be done with the less obvious \"PCRE,\n!LIBPCRE2\", which while semantically the same is more confusing, and\nwould lead to bugs if PCRE v3 is ever released as the tests would mean\nv1, not any non-v2 version.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nAs noted on-list I changed nothing here in the code, but noted in the\ncommit message why I'm keeping LIBPCRE1.\n\n t/README      | 12 ++++++++++++\n t/test-lib.sh |  2 ++\n 2 files changed, 14 insertions(+)\n\ndiff --git a/t/README b/t/README\nindex 4b079e4494..599cd9808c 100644\n--- a/t/README\n+++ b/t/README\n@@ -808,6 +808,18 @@ use these, and \"test_set_prereq\" for how to define your own.\n    Git was compiled with support for PCRE. Wrap any tests\n    that use git-grep --perl-regexp or git-grep -P in these.\n \n+ - LIBPCRE1\n+\n+   Git was compiled with PCRE v1 support via\n+   USE_LIBPCRE1=YesPlease. Wrap any PCRE using tests that for some\n+   reason need v1 of the PCRE library instead of v2 in these.\n+\n+ - LIBPCRE2\n+\n+   Git was compiled with PCRE v2 support via\n+   USE_LIBPCRE2=YesPlease. Wrap any PCRE using tests that for some\n+   reason need v2 of the PCRE library instead of v1 in these.\n+\n  - CASE_INSENSITIVE_FS\n \n    Test is run on a case insensitive file system.\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 116bd6a70c..e7065df2bb 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1028,6 +1028,8 @@ test -z \"$NO_PERL\" && test_set_prereq PERL\n test -z \"$NO_PTHREADS\" && test_set_prereq PTHREADS\n test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n test -n \"$USE_LIBPCRE1$USE_LIBPCRE2\" && test_set_prereq PCRE\n+test -n \"$USE_LIBPCRE1\" && test_set_prereq LIBPCRE1\n+test -n \"$USE_LIBPCRE2\" && test_set_prereq LIBPCRE2\n test -z \"$NO_GETTEXT\" && test_set_prereq GETTEXT\n \n # Can we rely on git's output in the C locale?\n-- \n2.15.0.403.gc27cc4dac6\n\n"},{"id":"333383","messageId":"20171123141658.13010-2-avarab@gmail.com","threadId":"47296","inReplyTo":"20171123141658.13010-1-avarab@gmail.com","subject":"[PATCH v2 2/2] grep: fix segfault under -P + PCRE2 <=10.30 + (*NO_JIT)","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-11-23T14:16:58Z","receivedAt":"2017-11-23T14:17:20Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Fix a bug in the compilation of PCRE2 patterns under JIT (the most\ncommon runtime configuration). Any pattern with a (*NO_JIT) verb would\nsegfault in any currently released PCRE2 version:\n\n    $ git grep -P '(*NO_JIT)hi.*there'\n    Segmentation fault\n\nThat this segfaulted was a bug in PCRE2 itself, after reporting it[1]\non pcre-dev it's been fixed in a yet-to-be-released version of\nPCRE (presumably released first as 10.31). Now it'll die with:\n\n    $ git grep -P '(*NO_JIT)hi.*there'\n    fatal: pcre2_jit_match failed with error code -45: bad JIT option\n\nBut the cause of the bug is in our own code dating back to my\n94da9193a6 (\"grep: add support for PCRE v2\", 2017-06-01).\n\nAs explained at more length in the comment being added here, it isn't\nsufficient to just check pcre2_config() to see whether the JIT should\nbe used, pcre2_pattern_info() also has to be asked.\n\nThis is something I discovered myself when fiddling around with PCRE2\nverbs in patterns passed to git. I don't expect that any user of git\nhas encountered this given the obscurity of passing PCRE2 verbs\nthrough to the library, along with the relative obscurity of (*NO_JIT)\nitself.\n\n1. \"How am I supposed to use PCRE2 JIT in the face of (*NO_JIT) ?\"\n   (<CACBZZX5mMqDuWuFmi7sRBp3wH6CFyd-ghACukd=v0NN=rBMnJg@mail.gmail.com> &\n    https://lists.exim.org/lurker/thread/20171123.101502.7f0d38ca.en.html)\n   on the pcre-dev mailing list\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nIncorporates feedback from Eric & Simon. Thanks both. I also amended\nthe commit message / comment to note that this was also a bug in PCRE2\nupstream, which has been fixed after I reported it.\n\n grep.c          | 26 ++++++++++++++++++++++++++\n t/t7810-grep.sh |  6 ++++++\n 2 files changed, 32 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex d0b9b6cdfa..e8ae0b5d8f 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -477,6 +477,8 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt\n \tint options = PCRE2_MULTILINE;\n \tconst uint8_t *character_tables = NULL;\n \tint jitret;\n+\tint patinforet;\n+\tsize_t jitsizearg;\n \n \tassert(opt->pcre2);\n \n@@ -511,6 +513,30 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt\n \t\tjitret = pcre2_jit_compile(p->pcre2_pattern, PCRE2_JIT_COMPLETE);\n \t\tif (jitret)\n \t\t\tdie(\"Couldn't JIT the PCRE2 pattern '%s', got '%d'\\n\", p->pattern, jitret);\n+\n+\t\t/*\n+\t\t * The pcre2_config(PCRE2_CONFIG_JIT, ...) call just\n+\t\t * tells us whether the library itself supports JIT,\n+\t\t * but to see whether we're going to be actually using\n+\t\t * JIT we need to extract PCRE2_INFO_JITSIZE from the\n+\t\t * pattern *after* we do pcre2_jit_compile() above.\n+\t\t *\n+\t\t * This is because if the pattern contains the\n+\t\t * (*NO_JIT) verb (see pcre2syntax(3))\n+\t\t * pcre2_jit_compile() will exit early with 0. If we\n+\t\t * then proceed to call pcre2_jit_match() further down\n+\t\t * the line instead of pcre2_match() we'll either\n+\t\t * segfault (pre PCRE 10.31) or run into a fatal error\n+\t\t * (post PCRE2 10.31)\n+\t\t */\n+\t\tpatinforet = pcre2_pattern_info(p->pcre2_pattern, PCRE2_INFO_JITSIZE, &jitsizearg);\n+\t\tif (patinforet)\n+\t\t\tBUG(\"pcre2_pattern_info() failed: %d\", patinforet);\n+\t\tif (jitsizearg == 0) {\n+\t\t\tp->pcre2_jit_on = 0;\n+\t\t\treturn;\n+\t\t}\n+\n \t\tp->pcre2_jit_stack = pcre2_jit_stack_create(1, 1024 * 1024, NULL);\n \t\tif (!p->pcre2_jit_stack)\n \t\t\tdie(\"Couldn't allocate PCRE2 JIT stack\");\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 2a6679c2f5..c8ff50cc30 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -1110,6 +1110,12 @@ test_expect_success PCRE 'grep -P pattern' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success LIBPCRE2 \"grep -P with (*NO_JIT) doesn't error out\" '\n+\tgit grep -P \"(*NO_JIT)\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+\n+'\n+\n test_expect_success !PCRE 'grep -P pattern errors without PCRE' '\n \ttest_must_fail git grep -P \"foo.*bar\"\n '\n-- \n2.15.0.403.gc27cc4dac6\n\n"}]}