From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31409 invoked from network); 28 Feb 2022 17:19:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Feb 2022 17:19:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1646068749; b=ZrH6MW2IM2awDSyj5z0otb4Y6RmoLGRlehepo/rSxXUGTS8y8siXzKCselWeaYLLnkhttV4FSt SaRc01HEkAxnRqWj1RdTfKH9EX+uHL4GiCIXStF9mAnj8cAWetcCDLMxIeopOyfKGFcvjcuSMM Rm8uDdfA9iUo7RLEcnHm9jgiQiD9SBHrErEuxcEMZvTwLT6M9VDNdsxilqUe7BP6NBtijPScGH tT9eziu3NJdR+w5/2LsNVygGDO5fotyWmbmd5SPkV8gqys6SflQzwQAScWDdnu+WqFYToQVsVp iFLEpOREBJOpibUObriB+lNsFUslTViK/74hGOoD3QFcDg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtp6.ctinetworks.com) smtp.remote-ip=205.166.61.199; dmarc=none header.from=meer.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1646068749; bh=p2PXA84jHjQ4PggoJICGkY9Gk7epY7DzfpEDS/ACj6I=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version: References:From:Cc:Subject:To:Message-ID:Date:DKIM-Signature; b=NIvRIDrheglvq7/bWpIZLkhUHvlwtbem85o7mYEVvQbbYPEz5J62td+SBSiEse4ClpXufiWLaa M0hHWLQziFrADbyg3Yl5zI1Sl/DqOsIquDiiCNCigj67sxLh0TiCVdTPDZ66OpxnBBX/7WU08p OZqtBteAUgHPFYMDAuEaQ6iUl8PmeQZLph+wJ1t7LN+r8ViEcxJ2I2+shPySeBkwseQw796DqA H5T+YGD24mPunO41g1XeSX/pt+ginR2iW2f9dImbUbow6OA6muV1J6okuAfbz2/E3/5valB9qq vAoCqJqjIS+pZoF/HsDL3avQai0d8P7u9rzLW+64CtGCLA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Mime-Version:References:From:CC:Subject:To:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To; bh=VGdL/6N4fRme3LJM5sCvQ2Izw/PaKbHYUFv5U9+nL8k=; b=Am261dd7Q78xuV7X4A0xCuo5f/ 8453F0Kbpq4GMOyfmBmC7faFq+VoyH0Vupmw/rlkJPG1H8F1+IQhKIPtOvvw5Is3rMVka3qEw5ntC i6rzbgl+38DQJMccEMnXNCv/P1rkOJasrEoOa0PJKv01Zf3mLqcxV38jLnRiPEvBH/jmY7POG8szV wjIpy6LHKyYAvEVZVxNvUb9RZbbZ/I1D1NwNnyC7i87GwCGJDr4t4Eht0D1n9H/WfiUmuCY87aw2r Xhp91BwKPPnHlo+K1b6LRZYHc88IoGo72/BU0u/y7Ui4K9icgxEXkf1xNnl4CrxcvttEkuXNEXx+V EMxnwmZw==; Received: from authenticated user by zero.zsh.org with local id 1nOjfv-0003ks-1h; Mon, 28 Feb 2022 17:19:07 +0000 Authentication-Results: zsh.org; iprev=pass (smtp6.ctinetworks.com) smtp.remote-ip=205.166.61.199; dmarc=none header.from=meer.net; arc=none Received: from smtp6.ctinetworks.com ([205.166.61.199]:45080) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nOjIn-0002rp-PV; Mon, 28 Feb 2022 16:55:15 +0000 Received: from localhost (unknown [117.254.35.192]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: enometh@meer.net) by smtp6.ctinetworks.com (Postfix) with ESMTPSA id 8ADFE860C0; Mon, 28 Feb 2022 11:55:04 -0500 (EST) Date: Mon, 28 Feb 2022 22:24:57 +0530 (IST) Message-Id: <20220228.222457.2128269761925169168.enometh@meer.net> To: zsh-workers@zsh.org Subject: Re: PATCH: pattern incremental search CC: p.w.stephenson@ntlworld.com From: Madhu References: <26439.1209238907@pws-pc> <1514882387.357077.1640002234148@mail2.virginmedia.com> X-Mailer: Mew version 6.8 on Emacs 29.0.50 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_Feb_28_22_24_57_2022_832)--" Content-Transfer-Encoding: 7bit X-ctinetworks-Information: Please contact the ISP for more information X-ctinetworks-MailScanner-ID: 8ADFE860C0.A8C6C X-ctinetworks-VirusCheck: Found to be clean X-ctinetworks-SpamCheck: X-ctinetworks-Watermark: 1646931311.51945@W9OKdthcCRupjI4l4WiIjQ X-Validation-by: kb@spambri.de X-Seq: 49781 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: ----Next_Part(Mon_Feb_28_22_24_57_2022_832)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit * 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 wrote: >> On 4/26/08, Peter Stephenson 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 :) ----Next_Part(Mon_Feb_28_22_24_57_2022_832)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="glob.c-fix-segfault-on-non-multibyte-history-inc.patch" >From 81e59a30fa593a8bfd10ad8a28a7475803d5f839 Mon Sep 17 00:00:00 2001 From: Madhu 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_Part(Mon_Feb_28_22_24_57_2022_832)----