diff options
author | Peter Stephenson <pws@zsh.org> | 2017-01-06 17:42:13 +0000 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2017-01-06 17:42:13 +0000 |
commit | 48cadf48ff9c61ce09e826ad9a58e250e999a262 (patch) | |
tree | 133c6364dbe86de4675ecbc5b7ba2191ea31fa79 | |
parent | 9d87cd948edad4634cabe44ed188e7222b7f9d28 (diff) | |
download | zsh-48cadf48ff9c61ce09e826ad9a58e250e999a262.tar.gz zsh-48cadf48ff9c61ce09e826ad9a58e250e999a262.tar.xz zsh-48cadf48ff9c61ce09e826ad9a58e250e999a262.zip |
40285: Be more careful with pattern allocation in history isearch.
If there are ZLE hooks to be called, they may use patterns, in which case it's not safe to allocate the isearch pattern in the static buffer.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Src/Zle/zle_hist.c | 11 |
2 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog index 0d0d95bf1..a797267f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-01-06 Peter Stephenson <p.stephenson@samsung.com> + + * m0viefreak: 40285: Src/Zle/zle_hist.c: more care needed + managing patterns in history isearch if there are hooks + around. + 2017-01-05 Daniel Shahaf <d.s@daniel.shahaf.name> * 40270 (after 39995): Src/params.c: Add cross-reference for diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c index abd6e1749..434735de9 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 |