summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2016-08-24 13:32:18 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2016-08-24 13:32:18 +0000
commit8e774b6c184bdff850f6889865a0d4f0522638a4 (patch)
tree4cec09a7ed0039027e9f46a47b7ed1737a42809e /bin/ksh
parent81a250269621f2dc44c4c16e6f887063bd0be941 (diff)
Avoid recursively calling c_fc(). Fixes a core dump from "r r" and
other edge cases found by gsoares@. OK tb@ gsoares@
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/history.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/bin/ksh/history.c b/bin/ksh/history.c
index 78f9fb7468e..be9874f0107 100644
--- a/bin/ksh/history.c
+++ b/bin/ksh/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.56 2015/12/30 09:07:00 tedu Exp $ */
+/* $OpenBSD: history.c,v 1.57 2016/08/24 13:32:17 millert Exp $ */
/*
* command history
@@ -60,9 +60,15 @@ c_fc(char **wp)
struct temp *tf = NULL;
char *p, *editor = NULL;
int gflag = 0, lflag = 0, nflag = 0, sflag = 0, rflag = 0;
- int optc;
+ int optc, ret;
char *first = NULL, *last = NULL;
char **hfirst, **hlast, **hp;
+ static int depth;
+
+ if (depth != 0) {
+ bi_errorf("history function called recursively");
+ return 1;
+ }
if (!Flag(FTALKING_I)) {
bi_errorf("history functions not available");
@@ -145,7 +151,10 @@ c_fc(char **wp)
hist_get_newest(false);
if (!hp)
return 1;
- return hist_replace(hp, pat, rep, gflag);
+ depth++;
+ ret = hist_replace(hp, pat, rep, gflag);
+ depth--;
+ return ret;
}
if (editor && (lflag || nflag)) {
@@ -229,7 +238,6 @@ c_fc(char **wp)
/* XXX: source should not get trashed by this.. */
{
Source *sold = source;
- int ret;
ret = command(editor ? editor : "${FCEDIT:-/bin/ed} $_", 0);
source = sold;
@@ -265,7 +273,10 @@ c_fc(char **wp)
shf_close(shf);
*xp = '\0';
strip_nuls(Xstring(xs, xp), Xlength(xs, xp));
- return hist_execute(Xstring(xs, xp));
+ depth++;
+ ret = hist_execute(Xstring(xs, xp));
+ depth--;
+ return ret;
}
}