about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Src/builtin.c14
2 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f39563727..2356b734a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-07-25  Peter Stephenson  <pws@csr.com>
+
+	* 25338: Src/builtin.c: disallow fc editing of the current
+	history line which has bad effects on stack usage and temporary
+	files.
+
 2008-07-23  Clint Adams  <clint@zsh.org>
 
 	* 25330: Doc/Zsh/mod_curses.yo: fix description of
diff --git a/Src/builtin.c b/Src/builtin.c
index c7ed283a9..9465bb5a0 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1446,6 +1446,20 @@ bin_fc(char *nam, char **argv, Options ops, int func)
 	    unqueue_signals();
 	    zwarnnam("fc", "can't open temp file: %e", errno);
 	} else {
+	    /*
+	     * Nasty behaviour results if we use the current history
+	     * line here.  Treat it as if it doesn't exist, unless
+	     * that gives us an empty range.
+	     */
+	    if (last >= curhist) {
+		last = curhist - 1;
+		if (first > last) {
+		    unqueue_signals();
+		    zwarnnam("fc", "invalid use of current history line");
+		    unlink(fil);
+		    return 1;
+		}
+	    }
 	    ops->ind['n'] = 1;	/* No line numbers here. */
 	    if (!fclist(out, ops, first, last, asgf, pprog)) {
 		char *editor;