psss / rpms / zsh

Forked from rpms/zsh 5 years ago
Clone
914fcff
From e56d3b33b50c42301925288af98b18aeb56f83cc Mon Sep 17 00:00:00 2001
914fcff
From: Peter Stephenson <pws@zsh.org>
914fcff
Date: Fri, 6 Jan 2017 17:42:13 +0000
914fcff
Subject: [PATCH] 40285: Be more careful with pattern allocation in history
914fcff
 isearch.
914fcff
914fcff
If there are ZLE hooks to be called, they may use patterns, in
914fcff
which case it's not safe to allocate the isearch pattern in the
914fcff
static buffer.
914fcff
914fcff
Upstream-commit: 48cadf48ff9c61ce09e826ad9a58e250e999a262
914fcff
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
914fcff
---
914fcff
 Src/Zle/zle_hist.c | 11 +++++++----
914fcff
 1 file changed, 7 insertions(+), 4 deletions(-)
914fcff
914fcff
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
914fcff
index abd6e17..434735d 100644
914fcff
--- a/Src/Zle/zle_hist.c
914fcff
+++ b/Src/Zle/zle_hist.c
914fcff
@@ -1220,13 +1220,12 @@ doisearch(char **args, int dir, int pattern)
914fcff
 		char *patbuf = ztrdup(sbuf);
914fcff
 		char *patstring;
914fcff
 		/*
914fcff
-		 * Use static pattern buffer since we don't need
914fcff
-		 * to maintain it and won't call other pattern functions
914fcff
-		 * meanwhile.
914fcff
+		 * Do not use static pattern buffer (PAT_STATIC) since we call zle hooks,
914fcff
+		 * which might call other pattern functions. Use PAT_ZDUP instead.
914fcff
 		 * Use PAT_NOANCH because we don't need the match
914fcff
 		 * anchored to the end, even if it is at the start.
914fcff
 		 */
914fcff
-		int patflags = PAT_STATIC|PAT_NOANCH;
914fcff
+		int patflags = PAT_ZDUP|PAT_NOANCH;
914fcff
 		if (sbuf[0] == '^') {
914fcff
 		    /*
914fcff
 		     * We'll handle the anchor later when
914fcff
@@ -1521,6 +1520,7 @@ doisearch(char **args, int dir, int pattern)
914fcff
 		    if (only_one || !top_spot || old_sbptr != sbptr)
914fcff
 			break;
914fcff
 		}
914fcff
+		freepatprog(patprog);
914fcff
 		patprog = NULL;
914fcff
 		nosearch = 1;
914fcff
 		skip_pos = 0;
914fcff
@@ -1632,6 +1632,7 @@ doisearch(char **args, int dir, int pattern)
914fcff
 	    }
914fcff
 	    strcpy(sbuf + sbptr, paste);
914fcff
 	    sbptr += pastelen;
914fcff
+	    freepatprog(patprog);
914fcff
 	    patprog = NULL;
914fcff
 	    free(paste);
914fcff
 	} else if (cmd == Th(z_acceptsearch)) {
914fcff
@@ -1682,6 +1683,7 @@ doisearch(char **args, int dir, int pattern)
914fcff
 	     * always valid at this point.
914fcff
 	     */
914fcff
 	    sbptr += zlecharasstring(LASTFULLCHAR, sbuf + sbptr);
914fcff
+	    freepatprog(patprog);
914fcff
 	    patprog = NULL;
914fcff
 	}
914fcff
 	if (feep)
914fcff
@@ -1702,6 +1704,7 @@ doisearch(char **args, int dir, int pattern)
914fcff
     zsfree(okeymap);
914fcff
     if (matchlist)
914fcff
 	freematchlist(matchlist);
914fcff
+    freepatprog(patprog);
914fcff
     isearch_active = 0;
914fcff
     /*
914fcff
      * Don't allow unused characters provided as a string to the
914fcff
-- 
914fcff
2.9.4
914fcff