From: Mikael Berthe <mikael.berthe@lilotux.net>
To: zsh-workers@zsh.org
Subject: Segfault with PCRE (Re: Strange behavior of [[)
Date: Sat, 23 Apr 2016 11:51:36 +0200 [thread overview]
Message-ID: <20160423095136.GA5286@lilotux.net> (raw)
In-Reply-To: <9BF380A3-CAEB-46FB-8598-4E80DF45E79D@kba.biglobe.ne.jp>
Hello,
The following lines cause a segfault in zsh on my machines:
setopt re_match_pcre
s=test.txt
[[ $s =~ '^(.*_)?(test)' ]] && echo $match[2]
This occurs only when the first group doesn't match (works fine with
s=1_test.txt).
I think this is related to the patch 37515 (commit 5eae5b58b1b99946),
see below:
* Jun T. <takimoto-j@kba.biglobe.ne.jp> [2016-01-08 14:09 +0100]:
> pcre.c has the same problem:
>
> % setopt re_match_pcre
> % [[ $'\ua0' =~ . ]] && echo OK
> (zsh hangs; 100% CPU usage)
>
> The following is a copy of the patch to regex.c in workers/35448.
> Also added a simple test in V07pcre.ztst.
>
> diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c
(...)
Here ovec[2] = -1 (because there was no match for '(.**)?'),
and we have ipair = ovec + 2, so leftlen is set to -1 below.
> @@ -219,17 +226,23 @@ zpcre_get_substrings(char *arg, int *ovec, int ret, char *matchvar,
> ptr = arg;
> offs = 0;
> /* Find the start offset */
> - MB_METACHARINIT();
> - while (ptr < arg + ipair[0]) {
> + MB_CHARINIT();
> + leftlen = ipair[0];
> + while (leftlen) {
> offs++;
> - ptr += MB_METACHARLEN(ptr);
> + clen = MB_CHARLEN(ptr, leftlen);
> + ptr += clen;
> + leftlen -= clen;
> }
The following patch fixes the segfault for me:
diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c
index e23ab57..5fd6796 100644
--- a/Src/Modules/pcre.c
+++ b/Src/Modules/pcre.c
@@ -228,7 +228,7 @@ zpcre_get_substrings(char *arg, int *ovec, int ret, char *matchvar,
/* Find the start offset */
MB_CHARINIT();
leftlen = ipair[0];
- while (leftlen) {
+ while (leftlen > 0) {
offs++;
clen = MB_CHARLEN(ptr, leftlen);
ptr += clen;
Regards,
--
Mikael
next prev parent reply other threads:[~2016-04-23 9:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-10 3:27 Strange behavior of [[ Maxime Arthaud
2015-06-10 5:31 ` Bart Schaefer
2015-06-10 8:55 ` Peter Stephenson
2015-06-11 16:59 ` Peter Stephenson
2015-06-22 15:56 ` m0viefreak
2015-06-22 16:29 ` Peter Stephenson
2016-01-08 13:09 ` Jun T.
2016-04-23 9:51 ` Mikael Berthe [this message]
2016-04-23 21:22 ` Segfault with PCRE (Re: Strange behavior of [[) Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160423095136.GA5286@lilotux.net \
--to=mikael.berthe@lilotux.net \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).