f686d7
From a361a5ac293c9422f953c3d59e53f07e195740d3 Mon Sep 17 00:00:00 2001
f686d7
From: "Barton E. Schaefer" <schaefer@zsh.org>
f686d7
Date: Thu, 6 Nov 2014 10:50:20 -0800
f686d7
Subject: [PATCH 1/5] 33614 (based on RedHat BZ-978613): signal safety when
f686d7
 updating global state in execshfunc()
f686d7
f686d7
Upstream-commit: 7abd611a2396bad9d93d18681a2c59cb1ea0e158
f686d7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
f686d7
---
f686d7
 Src/exec.c | 6 ++++++
f686d7
 1 file changed, 6 insertions(+)
f686d7
f686d7
diff --git a/Src/exec.c b/Src/exec.c
f686d7
index 28da5c3..60ee4b8 100644
f686d7
--- a/Src/exec.c
f686d7
+++ b/Src/exec.c
f686d7
@@ -4392,6 +4392,7 @@ execshfunc(Shfunc shf, LinkList args)
f686d7
 	fputc('\n', xtrerr);
f686d7
 	fflush(xtrerr);
f686d7
     }
f686d7
+    queue_signals();
f686d7
     ocs = cmdstack;
f686d7
     ocsp = cmdsp;
f686d7
     cmdstack = (unsigned char *) zalloc(CMDSTACKSZ);
f686d7
@@ -4399,7 +4400,11 @@ execshfunc(Shfunc shf, LinkList args)
f686d7
     if ((osfc = sfcontext) == SFC_NONE)
f686d7
 	sfcontext = SFC_DIRECT;
f686d7
     xtrerr = stderr;
f686d7
+    unqueue_signals();
f686d7
+
f686d7
     doshfunc(shf, args, 0);
f686d7
+
f686d7
+    queue_signals();
f686d7
     sfcontext = osfc;
f686d7
     free(cmdstack);
f686d7
     cmdstack = ocs;
f686d7
@@ -4407,6 +4412,7 @@ execshfunc(Shfunc shf, LinkList args)
f686d7
 
f686d7
     if (!list_pipe)
f686d7
 	deletefilelist(last_file_list, 0);
f686d7
+    unqueue_signals();
f686d7
 }
f686d7
 
f686d7
 /* Function to execute the special type of command that represents an *
f686d7
-- 
f686d7
2.4.0
f686d7
f686d7
f686d7
From 236bb914d24e6588d12c3bf66bd06c6416832b8f Mon Sep 17 00:00:00 2001
f686d7
From: "Barton E. Schaefer" <schaefer@zsh.org>
f686d7
Date: Fri, 20 Feb 2015 18:45:36 -0800
f686d7
Subject: [PATCH 2/5] 34590: queue_signals() around more scopes that manipulate
f686d7
 global state
f686d7
f686d7
Upstream-commit: a4ff8e69570cbdb8e7d5bf1d5cc4000ffe63e15e
f686d7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
f686d7
---
f686d7
 Src/exec.c |  4 +++-
f686d7
 Src/text.c | 15 +++++++++++++++
f686d7
 2 files changed, 18 insertions(+), 1 deletion(-)
f686d7
f686d7
diff --git a/Src/exec.c b/Src/exec.c
f686d7
index 60ee4b8..83b9083 100644
f686d7
--- a/Src/exec.c
f686d7
+++ b/Src/exec.c
f686d7
@@ -2280,6 +2280,7 @@ addvars(Estate state, Wordcode pc, int addflags)
f686d7
 void
f686d7
 setunderscore(char *str)
f686d7
 {
f686d7
+    queue_signals();
f686d7
     if (str && *str) {
f686d7
 	int l = strlen(str) + 1, nl = (l + 31) & ~31;
f686d7
 
f686d7
@@ -2297,6 +2298,7 @@ setunderscore(char *str)
f686d7
 	*zunderscore = '\0';
f686d7
 	underscoreused = 1;
f686d7
     }
f686d7
+    unqueue_signals();
f686d7
 }
f686d7
 
f686d7
 /* These describe the type of expansions that need to be done on the words
f686d7
@@ -5056,7 +5058,7 @@ execsave(void)
f686d7
 {
f686d7
     struct execstack *es;
f686d7
 
f686d7
-    es = (struct execstack *) malloc(sizeof(struct execstack));
f686d7
+    es = (struct execstack *) zalloc(sizeof(struct execstack));
f686d7
     es->list_pipe_pid = list_pipe_pid;
f686d7
     es->nowait = nowait;
f686d7
     es->pline_level = pline_level;
f686d7
diff --git a/Src/text.c b/Src/text.c
f686d7
index f55553e..8f8eb34 100644
f686d7
--- a/Src/text.c
f686d7
+++ b/Src/text.c
f686d7
@@ -173,6 +173,8 @@ getpermtext(Eprog prog, Wordcode c, int start_indent)
f686d7
 {
f686d7
     struct estate s;
f686d7
 
f686d7
+    queue_signals();
f686d7
+
f686d7
     if (!c)
f686d7
 	c = prog->prog;
f686d7
 
f686d7
@@ -193,6 +195,9 @@ getpermtext(Eprog prog, Wordcode c, int start_indent)
f686d7
     *tptr = '\0';
f686d7
     freeeprog(prog);		/* mark as unused */
f686d7
     untokenize(tbuf);
f686d7
+
f686d7
+    unqueue_signals();
f686d7
+
f686d7
     return tbuf;
f686d7
 }
f686d7
 
f686d7
@@ -206,6 +211,8 @@ getjobtext(Eprog prog, Wordcode c)
f686d7
 
f686d7
     struct estate s;
f686d7
 
f686d7
+    queue_signals();
f686d7
+
f686d7
     if (!c)
f686d7
 	c = prog->prog;
f686d7
 
f686d7
@@ -224,6 +231,9 @@ getjobtext(Eprog prog, Wordcode c)
f686d7
     *tptr = '\0';
f686d7
     freeeprog(prog);		/* mark as unused */
f686d7
     untokenize(jbuf);
f686d7
+
f686d7
+    unqueue_signals();
f686d7
+
f686d7
     return jbuf;
f686d7
 }
f686d7
 
f686d7
@@ -879,6 +889,9 @@ getredirs(LinkList redirs)
f686d7
 	">", ">|", ">>", ">>|", "&>", "&>|", "&>>", "&>>|", "<>", "<",
f686d7
 	"<<", "<<-", "<<<", "<&", ">&", NULL /* >&- */, "<", ">"
f686d7
     };
f686d7
+
f686d7
+    queue_signals();
f686d7
+
f686d7
     taddchr(' ');
f686d7
     for (n = firstnode(redirs); n; incnode(n)) {
f686d7
 	Redir f = (Redir) getdata(n);
f686d7
@@ -966,4 +979,6 @@ getredirs(LinkList redirs)
f686d7
 	}
f686d7
     }
f686d7
     tptr--;
f686d7
+
f686d7
+    unqueue_signals();
f686d7
 }
f686d7
-- 
f686d7
2.4.0
f686d7
f686d7
f686d7
From 2e60901b1733929619cccce6cd66898520fd3015 Mon Sep 17 00:00:00 2001
f686d7
From: "Barton E. Schaefer" <schaefer@zsh.org>
f686d7
Date: Thu, 26 Sep 2013 21:27:27 -0700
f686d7
Subject: [PATCH 3/5] 31772: queue_signals() to prevent re-entry into
f686d7
 endparamscope().
f686d7
f686d7
Upstream-commit: ae92cadc75fbf7e8ec356cf09d3f73db9868424b
f686d7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
f686d7
---
f686d7
 Src/params.c | 2 ++
f686d7
 1 file changed, 2 insertions(+)
f686d7
f686d7
diff --git a/Src/params.c b/Src/params.c
f686d7
index 8649178..d6711e4 100644
f686d7
--- a/Src/params.c
f686d7
+++ b/Src/params.c
f686d7
@@ -4667,10 +4667,12 @@ startparamscope(void)
f686d7
 mod_export void
f686d7
 endparamscope(void)
f686d7
 {
f686d7
+    queue_signals();
f686d7
     locallevel--;
f686d7
     /* This pops anything from a higher locallevel */
f686d7
     saveandpophiststack(0, HFILE_USE_OPTIONS);
f686d7
     scanhashtable(paramtab, 0, 0, 0, scanendscope, 0);
f686d7
+    unqueue_signals();
f686d7
 }
f686d7
 
f686d7
 /**/
f686d7
-- 
f686d7
2.4.1
f686d7
f686d7
f686d7
From 39dea2e735ae277c9e1238e5d17f3fbd0a08bb6f Mon Sep 17 00:00:00 2001
f686d7
From: Bart Schaefer <schaefer@zsh.org>
f686d7
Date: Thu, 17 Oct 2013 07:35:05 -0700
f686d7
Subject: [PATCH 4/5] 31832: make execrestore() more signal-safe.
f686d7
f686d7
Upstream-commit: 978b5bcc8d21fce58369f810ef73bdbc434f33e7
f686d7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
f686d7
---
f686d7
 Src/exec.c | 52 ++++++++++++++++++++++++++++------------------------
f686d7
 1 file changed, 28 insertions(+), 24 deletions(-)
f686d7
f686d7
diff --git a/Src/exec.c b/Src/exec.c
f686d7
index 83b9083..2f94052 100644
f686d7
--- a/Src/exec.c
f686d7
+++ b/Src/exec.c
f686d7
@@ -5087,30 +5087,34 @@ execsave(void)
f686d7
 void
f686d7
 execrestore(void)
f686d7
 {
f686d7
-    struct execstack *en;
f686d7
+    struct execstack *en = exstack;
f686d7
 
f686d7
     DPUTS(!exstack, "BUG: execrestore() without execsave()");
f686d7
-    list_pipe_pid = exstack->list_pipe_pid;
f686d7
-    nowait = exstack->nowait;
f686d7
-    pline_level = exstack->pline_level;
f686d7
-    list_pipe_child = exstack->list_pipe_child;
f686d7
-    list_pipe_job = exstack->list_pipe_job;
f686d7
-    strcpy(list_pipe_text, exstack->list_pipe_text);
f686d7
-    lastval = exstack->lastval;
f686d7
-    noeval = exstack->noeval;
f686d7
-    badcshglob = exstack->badcshglob;
f686d7
-    cmdoutpid = exstack->cmdoutpid;
f686d7
-    cmdoutval = exstack->cmdoutval;
f686d7
-    use_cmdoutval = exstack->use_cmdoutval;
f686d7
-    trap_return = exstack->trap_return;
f686d7
-    trap_state = exstack->trap_state;
f686d7
-    trapisfunc = exstack->trapisfunc;
f686d7
-    traplocallevel = exstack->traplocallevel;
f686d7
-    noerrs = exstack->noerrs;
f686d7
-    subsh_close = exstack->subsh_close;
f686d7
-    setunderscore(exstack->underscore);
f686d7
-    zsfree(exstack->underscore);
f686d7
-    en = exstack->next;
f686d7
-    free(exstack);
f686d7
-    exstack = en;
f686d7
+
f686d7
+    queue_signals();
f686d7
+    exstack = exstack->next;
f686d7
+
f686d7
+    list_pipe_pid = en->list_pipe_pid;
f686d7
+    nowait = en->nowait;
f686d7
+    pline_level = en->pline_level;
f686d7
+    list_pipe_child = en->list_pipe_child;
f686d7
+    list_pipe_job = en->list_pipe_job;
f686d7
+    strcpy(list_pipe_text, en->list_pipe_text);
f686d7
+    lastval = en->lastval;
f686d7
+    noeval = en->noeval;
f686d7
+    badcshglob = en->badcshglob;
f686d7
+    cmdoutpid = en->cmdoutpid;
f686d7
+    cmdoutval = en->cmdoutval;
f686d7
+    use_cmdoutval = en->use_cmdoutval;
f686d7
+    trap_return = en->trap_return;
f686d7
+    trap_state = en->trap_state;
f686d7
+    trapisfunc = en->trapisfunc;
f686d7
+    traplocallevel = en->traplocallevel;
f686d7
+    noerrs = en->noerrs;
f686d7
+    subsh_close = en->subsh_close;
f686d7
+    setunderscore(en->underscore);
f686d7
+    zsfree(en->underscore);
f686d7
+    free(en);
f686d7
+
f686d7
+    unqueue_signals();
f686d7
 }
f686d7
-- 
f686d7
2.4.1
f686d7
f686d7
f686d7
From 15ac5a43bb483ed753655c7985fbdb056745303b Mon Sep 17 00:00:00 2001
f686d7
From: "Barton E. Schaefer" <schaefer@zsh.org>
f686d7
Date: Tue, 30 Sep 2014 20:34:58 -0700
f686d7
Subject: [PATCH 5/5] 33298: make lexrestore() more signal-safe
f686d7
f686d7
Upstream-commit: 8727049674b1f39a8926c02dc74e9f19bbd70289
f686d7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
f686d7
---
f686d7
 Src/lex.c | 110 ++++++++++++++++++++++++++++++++------------------------------
f686d7
 1 file changed, 57 insertions(+), 53 deletions(-)
f686d7
f686d7
diff --git a/Src/lex.c b/Src/lex.c
f686d7
index ac87e5e..82bf848 100644
f686d7
--- a/Src/lex.c
f686d7
+++ b/Src/lex.c
f686d7
@@ -323,66 +323,70 @@ lexsave(void)
f686d7
 mod_export void
f686d7
 lexrestore(void)
f686d7
 {
f686d7
-    struct lexstack *ln;
f686d7
+    struct lexstack *ln = lstack;
f686d7
 
f686d7
     DPUTS(!lstack, "BUG: lexrestore() without lexsave()");
f686d7
-    incmdpos = lstack->incmdpos;
f686d7
-    incond = lstack->incond;
f686d7
-    incasepat = lstack->incasepat;
f686d7
-    dbparens = lstack->dbparens;
f686d7
-    isfirstln = lstack->isfirstln;
f686d7
-    isfirstch = lstack->isfirstch;
f686d7
-    histactive = lstack->histactive;
f686d7
-    histdone = lstack->histdone;
f686d7
-    lexflags = lstack->lexflags;
f686d7
-    stophist = lstack->stophist;
f686d7
-    chline = lstack->hline;
f686d7
-    hptr = lstack->hptr;
f686d7
+
f686d7
+    queue_signals();
f686d7
+    lstack = lstack->next;
f686d7
+
f686d7
+    if (!lstack) {
f686d7
+	/* Back to top level: don't need special ZLE value */
f686d7
+	DPUTS(ln->hline != zle_chline, "BUG: Ouch, wrong chline for ZLE");
f686d7
+	zle_chline = NULL;
f686d7
+    }
f686d7
+
f686d7
+    incmdpos = ln->incmdpos;
f686d7
+    incond = ln->incond;
f686d7
+    incasepat = ln->incasepat;
f686d7
+    dbparens = ln->dbparens;
f686d7
+    isfirstln = ln->isfirstln;
f686d7
+    isfirstch = ln->isfirstch;
f686d7
+    histactive = ln->histactive;
f686d7
+    histdone = ln->histdone;
f686d7
+    lexflags = ln->lexflags;
f686d7
+    stophist = ln->stophist;
f686d7
+    chline = ln->hline;
f686d7
+    hptr = ln->hptr;
f686d7
     if (cmdstack)
f686d7
-	free(cmdstack);
f686d7
-    cmdstack = lstack->cstack;
f686d7
-    cmdsp = lstack->csp;
f686d7
-    tok = lstack->tok;
f686d7
-    isnewlin = lstack->isnewlin;
f686d7
-    tokstr = lstack->tokstr;
f686d7
-    zshlextext = lstack->zshlextext;
f686d7
-    bptr = lstack->bptr;
f686d7
-    bsiz = lstack->bsiz;
f686d7
-    len = lstack->len;
f686d7
-    chwords = lstack->chwords;
f686d7
-    chwordlen = lstack->chwordlen;
f686d7
-    chwordpos = lstack->chwordpos;
f686d7
-    hwgetword = lstack->hwgetword;
f686d7
-    lexstop = lstack->lexstop;
f686d7
-    hdocs = lstack->hdocs;
f686d7
-    hgetc = lstack->hgetc;
f686d7
-    hungetc = lstack->hungetc;
f686d7
-    hwaddc = lstack->hwaddc;
f686d7
-    hwbegin = lstack->hwbegin;
f686d7
-    hwend = lstack->hwend;
f686d7
-    addtoline = lstack->addtoline;
f686d7
+	zfree(cmdstack, CMDSTACKSZ);
f686d7
+    cmdstack = ln->cstack;
f686d7
+    cmdsp = ln->csp;
f686d7
+    tok = ln->tok;
f686d7
+    isnewlin = ln->isnewlin;
f686d7
+    tokstr = ln->tokstr;
f686d7
+    zshlextext = ln->zshlextext;
f686d7
+    bptr = ln->bptr;
f686d7
+    bsiz = ln->bsiz;
f686d7
+    len = ln->len;
f686d7
+    chwords = ln->chwords;
f686d7
+    chwordlen = ln->chwordlen;
f686d7
+    chwordpos = ln->chwordpos;
f686d7
+    hwgetword = ln->hwgetword;
f686d7
+    lexstop = ln->lexstop;
f686d7
+    hdocs = ln->hdocs;
f686d7
+    hgetc = ln->hgetc;
f686d7
+    hungetc = ln->hungetc;
f686d7
+    hwaddc = ln->hwaddc;
f686d7
+    hwbegin = ln->hwbegin;
f686d7
+    hwend = ln->hwend;
f686d7
+    addtoline = ln->addtoline;
f686d7
     if (ecbuf)
f686d7
 	zfree(ecbuf, eclen);
f686d7
-    eclen = lstack->eclen;
f686d7
-    ecused = lstack->ecused;
f686d7
-    ecnpats = lstack->ecnpats;
f686d7
-    ecbuf = lstack->ecbuf;
f686d7
-    ecstrs = lstack->ecstrs;
f686d7
-    ecsoffs = lstack->ecsoffs;
f686d7
-    ecssub = lstack->ecssub;
f686d7
-    ecnfunc = lstack->ecnfunc;
f686d7
-    hlinesz = lstack->hlinesz;
f686d7
-    toklineno = lstack->toklineno;
f686d7
+    eclen = ln->eclen;
f686d7
+    ecused = ln->ecused;
f686d7
+    ecnpats = ln->ecnpats;
f686d7
+    ecbuf = ln->ecbuf;
f686d7
+    ecstrs = ln->ecstrs;
f686d7
+    ecsoffs = ln->ecsoffs;
f686d7
+    ecssub = ln->ecssub;
f686d7
+    ecnfunc = ln->ecnfunc;
f686d7
+    hlinesz = ln->hlinesz;
f686d7
+    toklineno = ln->toklineno;
f686d7
     errflag = 0;
f686d7
+    free(ln);
f686d7
 
f686d7
-    ln = lstack->next;
f686d7
-    if (!ln) {
f686d7
-	/* Back to top level: don't need special ZLE value */
f686d7
-	DPUTS(chline != zle_chline, "BUG: Ouch, wrong chline for ZLE");
f686d7
-	zle_chline = NULL;
f686d7
-    }
f686d7
-    free(lstack);
f686d7
-    lstack = ln;
f686d7
+    unqueue_signals();
f686d7
 }
f686d7
 
f686d7
 /**/
f686d7
-- 
f686d7
2.4.1
f686d7