From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18405 invoked by alias); 6 Jan 2017 17:29:05 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40285 Received: (qmail 25873 invoked from network); 6 Jan 2017 17:29:05 -0000 X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.26):SA:0(1.5/5.0):. Processed in 1.342455 secs); 06 Jan 2017 17:29:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_SOFTFAIL,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: m0viefreak.cm@googlemail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: softfail (ns1.primenet.com.au: transitioning SPF record at _netblocks3.google.com does not designate 66.111.4.26 as permitted sender) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:sender:subject:to:x-me-sender:x-me-sender :x-sasl-enc:x-sasl-enc; s=smtpout; bh=Wg75PouVk2CntmGJ7WrPZrDHnq I=; b=Qvy8euP3o3DjObhhBUsAV6K9GtJlEg7LQ2xrwha/yMCPoGZn89IiO814BN hRThqF0N75Ttkpovhf+VyYsoF3Rn1nU14BK9/82xBI8YJ9W+BMk/EOeSGnpfriLz nY+JJ+iaccMPC1qoLMK0BqtjJbhj+yn1+s5Gqh1DlRgQWLGF8= X-ME-Sender: X-Sasl-enc: 9VNLcJv/f237YCj7IDpVz85n7LAQ9MENQJpC9fvhR9mU 1483723736 Date: Fri, 6 Jan 2017 17:25:41 +0000 From: m0viefreak Sender: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] isearch: do not use PAT_STATIC since we call zle hooks Message-ID: <20170106172541.GA14113@fujitsu.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Using PAT_STATIC, any of the functions called in the hook that make use of patterns, implicitly change the pattern we use in the isearch loop. In the best case this results in pattern-not-found, in the worst case we get a dump. Use PAT_ZDUP instead and take care of freeing it again. Minimal reproducing example: % bindkey '^R' history-incremental-pattern-search-backward % evil_hook() { a=(); : ${a[(r)foo*]}; }; % zle -N zle-isearch-update evil_hook % : foo % : bar % : baz % type: <^R>b % : baz bck-i-search: b_ type: <^R> % : foo bck-i-search: b_ ': foo' is found instead of ': bar' because evil_hook modified the static pattern used in isearch. Related: zsh-syntax-highlighting issue which found this bug: https://github.com/zsh-users/zsh-syntax-highlighting/issues/407 --- Src/Zle/zle_hist.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index abd6e17..434735d 100644 --- a/Src/Zle/zle_hist.c +++ b/Src/Zle/zle_hist.c @@ -1220,13 +1220,12 @@ doisearch(char **args, int dir, int pattern) char *patbuf = ztrdup(sbuf); char *patstring; /* - * Use static pattern buffer since we don't need - * to maintain it and won't call other pattern functions - * meanwhile. + * Do not use static pattern buffer (PAT_STATIC) since we call zle hooks, + * which might call other pattern functions. Use PAT_ZDUP instead. * Use PAT_NOANCH because we don't need the match * anchored to the end, even if it is at the start. */ - int patflags = PAT_STATIC|PAT_NOANCH; + int patflags = PAT_ZDUP|PAT_NOANCH; if (sbuf[0] == '^') { /* * We'll handle the anchor later when @@ -1521,6 +1520,7 @@ doisearch(char **args, int dir, int pattern) if (only_one || !top_spot || old_sbptr != sbptr) break; } + freepatprog(patprog); patprog = NULL; nosearch = 1; skip_pos = 0; @@ -1632,6 +1632,7 @@ doisearch(char **args, int dir, int pattern) } strcpy(sbuf + sbptr, paste); sbptr += pastelen; + freepatprog(patprog); patprog = NULL; free(paste); } else if (cmd == Th(z_acceptsearch)) { @@ -1682,6 +1683,7 @@ doisearch(char **args, int dir, int pattern) * always valid at this point. */ sbptr += zlecharasstring(LASTFULLCHAR, sbuf + sbptr); + freepatprog(patprog); patprog = NULL; } if (feep) @@ -1702,6 +1704,7 @@ doisearch(char **args, int dir, int pattern) zsfree(okeymap); if (matchlist) freematchlist(matchlist); + freepatprog(patprog); isearch_active = 0; /* * Don't allow unused characters provided as a string to the -- 2.8.3