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