Blob Blame History Raw
From d1079f66e2fa1b238fa5b8dd038cb34f5ac001d0 Mon Sep 17 00:00:00 2001
From: Peter Stephenson <p.stephenson@samsung.com>
Date: Wed, 22 Jul 2015 14:38:03 +0100
Subject: [PATCH] 35854: prevent infinite recursion in ihungetc()

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 Src/hist.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Src/hist.c b/Src/hist.c
index 6725313..cf224cb 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--;
-- 
2.4.6