From: Madhu <enometh@meer.net>
To: zsh-workers@zsh.org
Cc: p.w.stephenson@ntlworld.com
Subject: Re: PATCH: pattern incremental search
Date: Mon, 28 Feb 2022 22:24:57 +0530 (IST) [thread overview]
Message-ID: <20220228.222457.2128269761925169168.enometh@meer.net> (raw)
In-Reply-To: <1514882387.357077.1640002234148@mail2.virginmedia.com>
[-- Attachment #1: Type: Text/Plain, Size: 1916 bytes --]
* Peter Stephenson <1514882387.357077.1640002234148@mail2.virginmedia.com> :
Wrote on Mon, 20 Dec 2021 12:10:34 +0000 (GMT):
> On 12/20/21, Mikael Magnusson <mikachu@gmail.com> wrote:
>> On 4/26/08, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
>>> - if (replstr) { + if (replstr || (fl & SUB_LIST)) {
>> Someone in the irc channel reported a crash on this strlen when
>> doing history-incremental-pattern-search-backward with any search,
>> and they can reproduce it with the latest git version too, they
>> posted this backtrace:
>
> That extra test doesn't look like it makes any sense --- I think it
> may just be in completely the wrong place and shouldn't be in
> get_match_ret() at all since it's similar to some checks in other
> places where we allow zero-length (but not NULL) strings for some edge
> cases in some variants of matching. We should probably just remove it
> and see what happens.
>
> pws
>
> diff --git a/Src/glob.c b/Src/glob.c index bee890caf..375671cea 100644
> --- a/Src/glob.c +++ b/Src/glob.c @@ -2549,7 +2549,7 @@
> get_match_ret(Imatchdata imd, int b, int e) e += add;
> /* Everything now refers to metafied lengths. */ - if (replstr ||
> (fl & SUB_LIST)) { + if (replstr) { if (fl & SUB_DOSUBST) { replstr =
> dupstring(replstr); singsub(&replstr);
This doesn't fix the segfault: which just gets postponed. Besides
this breaks incremental-pattern-search, which just stops working and
doesn't match anything in the history. Also, the segfault only occurs
when zsh is built without multibyte.
To hit the segfault, in a --disable-multibyte build
$ zsh -f
$ bindkey ^R history-incremental-pattern-search-backward
C-r .
Please consider the attached patch which 1) reverts the above fix, and
2) modifies the non-multibyte version of igetmatch to match the
multibyte version at some points. (Disclaimer. this is submitted with
no understanding of what the code does :)
[-- Attachment #2: glob.c-fix-segfault-on-non-multibyte-history-inc.patch --]
[-- Type: Text/X-Patch, Size: 2210 bytes --]
From 81e59a30fa593a8bfd10ad8a28a7475803d5f839 Mon Sep 17 00:00:00 2001
From: Madhu <enometh@net.meer>
Date: Mon, 28 Feb 2022 22:04:09 +0530
Subject: [PATCH] Src/glob.c: fix segfault on non-multibyte
history-incremental-pattern-search-backward
* Src/glob.c: (get_match_ret): revert the fix in
7f240e6aa9f5596a129474ba6294875dfe7ae264. With this patch ^R stops
working altogether. (igetmatch): cargo cult port code from the ifdef
MULTIBYTE_SUPPORT version to the ifndef MULTIBYTE_VERSION. This seems
to fix the segfault.
---
Src/glob.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/Src/glob.c b/Src/glob.c
index 375671c..7e2d810 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -2549,7 +2549,7 @@ get_match_ret(Imatchdata imd, int b, int e)
e += add;
/* Everything now refers to metafied lengths. */
- if (replstr) {
+ if (replstr || (fl & SUB_LIST)) {
if (fl & SUB_DOSUBST) {
replstr = dupstring(replstr);
singsub(&replstr);
@@ -3351,7 +3351,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr,
/* longest or smallest at start with substrings */
t = s;
if (fl & SUB_GLOBAL) {
- imd.repllist = newlinklist();
+ imd.repllist = (fl & SUB_LIST) ? znewlinklist() : newlinklist();
if (repllistp)
*repllistp = imd.repllist;
}
@@ -3481,6 +3481,7 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr,
* Results from get_match_ret in repllist are all metafied.
*/
s = *sp;
+ if (!(fl & SUB_LIST)) {
i = 0; /* start of last chunk we got from *sp */
for (nd = firstnode(imd.repllist); nd; incnode(nd)) {
rd = (Repldata) getdata(nd);
@@ -3503,16 +3504,22 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr,
memcpy(t, s + i, l - i);
start[lleft] = '\0';
*sp = (char *)start;
+ }
return 1;
}
+ if (fl & SUB_LIST) { /* safety: don't think this can happen */
+ return 0;
+ }
+
/* munge the whole string: no match, so no replstr */
imd.replstr = NULL;
imd.repllist = NULL;
*sp = get_match_ret(&imd, 0, 0);
- return 1;
+ return (fl & SUB_RETFAIL) ? 0 : 1;
}
+
/**/
#endif /* MULTIBYTE_SUPPORT */
--
2.35.1.dirty
next prev parent reply other threads:[~2022-02-28 17:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-26 19:41 Peter Stephenson
2008-04-26 20:22 ` Peter Stephenson
2008-04-26 20:35 ` Peter Stephenson
2008-04-26 20:51 ` Peter Stephenson
2008-04-26 23:52 ` Bart Schaefer
2008-04-28 1:35 ` Geoff Wing
[not found] ` <CAHYJk3Q5x=5Zn5kURXDDgLLoSEsro45_G=SZB-P+qX_qk7dn-Q@mail.gmail.com>
2021-12-20 3:40 ` Mikael Magnusson
2021-12-20 12:10 ` Peter Stephenson
2022-02-28 16:54 ` Madhu [this message]
2022-03-31 22:44 ` Lawrence Velázquez
2022-04-01 2:25 ` Madhu
2022-04-01 3:49 ` Bart Schaefer
2022-04-01 18:23 ` 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=20220228.222457.2128269761925169168.enometh@meer.net \
--to=enometh@meer.net \
--cc=p.w.stephenson@ntlworld.com \
--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).