summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-07-23 09:32:24 +0100
committerPeter Stephenson <pws@zsh.org>2015-07-23 09:32:24 +0100
commit49ff2e00dc3787b3575f392f53d90774f1dbbdce (patch)
tree788fb7477cba7838d283d8cf86c872c37a847f0c /Src/hist.c
parent9a82a8675782f137c8739bc950ac86dfe6a8dfd1 (diff)
downloadzsh-49ff2e00dc3787b3575f392f53d90774f1dbbdce.tar.gz
zsh-49ff2e00dc3787b3575f392f53d90774f1dbbdce.tar.xz
zsh-49ff2e00dc3787b3575f392f53d90774f1dbbdce.zip
35854: ensure history character unget doesn't recurse infinitely
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 672531394..cf224cb4e 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -136,6 +136,7 @@ mod_export int hist_skip_flags;
 #define HA_NOINC	(1<<1)	/* Don't store, curhist not incremented */
 #define HA_INWORD       (1<<2)  /* We're inside a word, don't add
 				   start and end markers */
+#define HA_UNGET        (1<<3)  /* Recursively ungetting */
 
 /* Array of word beginnings and endings in current history line. */
 
@@ -904,8 +905,13 @@ ihungetc(int c)
 
     while (!lexstop && !errflag) {
 	if (hptr[-1] != (char) c && stophist < 4 &&
-	    hptr > chline + 1 && hptr[-1] == '\n' && hptr[-2] == '\\')
-	    hungetc('\n'), hungetc('\\');
+	    hptr > chline + 1 && hptr[-1] == '\n' && hptr[-2] == '\\' &&
+	    !(histactive & HA_UNGET)) {
+	    histactive |= HA_UNGET;
+	    hungetc('\n');
+	    hungetc('\\');
+	    histactive &= ~HA_UNGET;
+	}
 
 	if (expanding) {
 	    zlemetacs--;