about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-07-25 08:55:26 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-07-25 08:55:26 +0000
commit897e8085ba81d85e00226713e65ae71e60f9f3e2 (patch)
treebfea4314d6f8aeb596cdaf3ac79ee49d4fcdcb3f /Src/builtin.c
parent8d17ae7628e234cde0a2432794692e65366b22af (diff)
downloadzsh-897e8085ba81d85e00226713e65ae71e60f9f3e2.tar.gz
zsh-897e8085ba81d85e00226713e65ae71e60f9f3e2.tar.xz
zsh-897e8085ba81d85e00226713e65ae71e60f9f3e2.zip
25338: disallow usage of current history line in fc
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c14
1 files changed, 14 insertions, 0 deletions
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;