mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-12-28 16:15:02 +01:00
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.
This commit is contained in:
parent
9d87cd948e
commit
48cadf48ff
2 changed files with 13 additions and 4 deletions
|
@ -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>
|
2017-01-05 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||||
|
|
||||||
* 40270 (after 39995): Src/params.c: Add cross-reference for
|
* 40270 (after 39995): Src/params.c: Add cross-reference for
|
||||||
|
|
|
@ -1220,13 +1220,12 @@ doisearch(char **args, int dir, int pattern)
|
||||||
char *patbuf = ztrdup(sbuf);
|
char *patbuf = ztrdup(sbuf);
|
||||||
char *patstring;
|
char *patstring;
|
||||||
/*
|
/*
|
||||||
* Use static pattern buffer since we don't need
|
* Do not use static pattern buffer (PAT_STATIC) since we call zle hooks,
|
||||||
* to maintain it and won't call other pattern functions
|
* which might call other pattern functions. Use PAT_ZDUP instead.
|
||||||
* meanwhile.
|
|
||||||
* Use PAT_NOANCH because we don't need the match
|
* Use PAT_NOANCH because we don't need the match
|
||||||
* anchored to the end, even if it is at the start.
|
* 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] == '^') {
|
if (sbuf[0] == '^') {
|
||||||
/*
|
/*
|
||||||
* We'll handle the anchor later when
|
* 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)
|
if (only_one || !top_spot || old_sbptr != sbptr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
freepatprog(patprog);
|
||||||
patprog = NULL;
|
patprog = NULL;
|
||||||
nosearch = 1;
|
nosearch = 1;
|
||||||
skip_pos = 0;
|
skip_pos = 0;
|
||||||
|
@ -1632,6 +1632,7 @@ doisearch(char **args, int dir, int pattern)
|
||||||
}
|
}
|
||||||
strcpy(sbuf + sbptr, paste);
|
strcpy(sbuf + sbptr, paste);
|
||||||
sbptr += pastelen;
|
sbptr += pastelen;
|
||||||
|
freepatprog(patprog);
|
||||||
patprog = NULL;
|
patprog = NULL;
|
||||||
free(paste);
|
free(paste);
|
||||||
} else if (cmd == Th(z_acceptsearch)) {
|
} else if (cmd == Th(z_acceptsearch)) {
|
||||||
|
@ -1682,6 +1683,7 @@ doisearch(char **args, int dir, int pattern)
|
||||||
* always valid at this point.
|
* always valid at this point.
|
||||||
*/
|
*/
|
||||||
sbptr += zlecharasstring(LASTFULLCHAR, sbuf + sbptr);
|
sbptr += zlecharasstring(LASTFULLCHAR, sbuf + sbptr);
|
||||||
|
freepatprog(patprog);
|
||||||
patprog = NULL;
|
patprog = NULL;
|
||||||
}
|
}
|
||||||
if (feep)
|
if (feep)
|
||||||
|
@ -1702,6 +1704,7 @@ doisearch(char **args, int dir, int pattern)
|
||||||
zsfree(okeymap);
|
zsfree(okeymap);
|
||||||
if (matchlist)
|
if (matchlist)
|
||||||
freematchlist(matchlist);
|
freematchlist(matchlist);
|
||||||
|
freepatprog(patprog);
|
||||||
isearch_active = 0;
|
isearch_active = 0;
|
||||||
/*
|
/*
|
||||||
* Don't allow unused characters provided as a string to the
|
* Don't allow unused characters provided as a string to the
|
||||||
|
|
Loading…
Reference in a new issue