Blame SOURCES/ksh-20120801-trapcom.patch

0c842d
diff -up ksh-20120801/src/cmd/ksh93/sh/subshell.c.orig ksh-20120801/src/cmd/ksh93/sh/subshell.c
0c842d
--- ksh-20120801/src/cmd/ksh93/sh/subshell.c.orig	2015-08-13 15:20:14.022167794 -0300
0c842d
+++ ksh-20120801/src/cmd/ksh93/sh/subshell.c	2015-08-13 15:21:43.263088168 -0300
0c842d
@@ -481,12 +481,12 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
0c842d
 {
0c842d
 	struct subshell sub_data;
0c842d
 	register struct subshell *sp = &sub_data;
0c842d
-	int jmpval,nsig=0,duped=0;
0c842d
+	int jmpval,isig,nsig=0,duped=0;
0c842d
 	long savecurenv = shp->curenv;
0c842d
 	int savejobpgid = job.curpgid;
0c842d
 	int *saveexitval = job.exitval;
0c842d
 	int16_t subshell;
0c842d
-	char *savsig;
0c842d
+	char **savsig;
0c842d
 	Sfio_t *iop=0;
0c842d
 	struct checkpt buff;
0c842d
 	struct sh_scoped savst;
0c842d
@@ -561,10 +561,13 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
0c842d
 		/* save trap table */
0c842d
 		shp->st.otrapcom = 0;
0c842d
 		shp->st.otrap = savst.trap;
0c842d
-		if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0])
0c842d
+		if((nsig=shp->st.trapmax)>0 || shp->st.trapcom[0])
0c842d
 		{
0c842d
-			nsig += sizeof(char*);
0c842d
-			memcpy(savsig=malloc(nsig),(char*)&shp->st.trapcom[0],nsig);
0c842d
+			++nsig;
0c842d
+			savsig = malloc(nsig * sizeof(char*));
0c842d
+			/* contents of shp->st.trapcom may change */
0c842d
+			for (isig = 0; isig < nsig; ++isig)
0c842d
+				savsig[isig] = shp->st.trapcom[isig] == Empty ? Empty : (shp->st.trapcom[isig] ? strdup(shp->st.trapcom[isig]) : NULL);
0c842d
 			/* this nonsense needed for $(trap) */
0c842d
 			shp->st.otrapcom = (char**)savsig;
0c842d
 		}
0c842d
@@ -732,7 +735,10 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
0c842d
 		shp->st.otrap = 0;
0c842d
 		if(nsig)
0c842d
 		{
0c842d
-			memcpy((char*)&shp->st.trapcom[0],savsig,nsig);
0c842d
+			for (isig = 0; isig < nsig; ++isig)
0c842d
+				if (shp->st.trapcom[isig] && shp->st.trapcom[isig]!=Empty)
0c842d
+					free(shp->st.trapcom[isig]);
0c842d
+			memcpy((char*)&shp->st.trapcom[0],savsig,nsig*sizeof(char*));
0c842d
 			free((void*)savsig);
0c842d
 		}
0c842d
 		shp->options = sp->options;
0c842d
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.orig ksh-20120801/src/cmd/ksh93/sh/xec.c
0c842d
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.orig	2015-08-13 15:22:09.821062351 -0300
0c842d
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c	2015-08-13 15:28:06.166662530 -0300
0c842d
@@ -3383,10 +3383,10 @@ int sh_funscope(int argn, char *argv[],i
0c842d
 	struct dolnod		*argsav=0,*saveargfor;
0c842d
 	struct sh_scoped	savst, *prevscope = shp->st.self;
0c842d
 	struct argnod		*envlist=0;
0c842d
-	int			jmpval;
0c842d
+	int			isig,jmpval;
0c842d
 	volatile int		r = 0;
0c842d
 	int			n;
0c842d
-	char 			*savstak;
0c842d
+	char 			**savsig;
0c842d
 	struct funenv		*fp = 0;
0c842d
 	struct checkpt	*buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
0c842d
 	Namval_t		*nspace = shp->namespace;
0c842d
@@ -3435,10 +3435,13 @@ int sh_funscope(int argn, char *argv[],i
0c842d
 	}
0c842d
 	shp->st.cmdname = argv[0];
0c842d
 	/* save trap table */
0c842d
-	if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0])
0c842d
+	if((nsig=shp->st.trapmax)>0 || shp->st.trapcom[0])
0c842d
 	{
0c842d
-		nsig += sizeof(char*);
0c842d
-		memcpy(savstak=stakalloc(nsig),(char*)&shp->st.trapcom[0],nsig);
0c842d
+		++nsig;
0c842d
+		savsig = malloc(nsig * sizeof(char*));
0c842d
+		/* contents of shp->st.trapcom may change */
0c842d
+		for (isig = 0; isig < nsig; ++isig)
0c842d
+			savsig[isig] = shp->st.trapcom[isig] == Empty ? Empty : (shp->st.trapcom[isig] ? strdup(shp->st.trapcom[isig]) : NULL);
0c842d
 	}
0c842d
 	sh_sigreset(0);
0c842d
 	argsav = sh_argnew(shp,argv,&saveargfor);
0c842d
@@ -3502,10 +3505,14 @@ int sh_funscope(int argn, char *argv[],i
0c842d
 	shp->topscope = (Shscope_t*)prevscope;
0c842d
 	nv_getval(sh_scoped(shp,IFSNOD));
0c842d
 	if(nsig)
0c842d
-		memcpy((char*)&shp->st.trapcom[0],savstak,nsig);
0c842d
+	{
0c842d
+		for (isig = 0; isig < nsig; ++isig)
0c842d
+			if (shp->st.trapcom[isig] && shp->st.trapcom[isig]!=Empty)
0c842d
+				free(shp->st.trapcom[isig]);
0c842d
+		memcpy((char*)&shp->st.trapcom[0],savsig,nsig*sizeof(char*));
0c842d
+		free((void*)savsig);
0c842d
+	}
0c842d
 	shp->trapnote=0;
0c842d
-	if(nsig)
0c842d
-		stakset(savstak,0);
0c842d
 	shp->options = options;
0c842d
 	shp->last_root = last_root;
0c842d
 	if(jmpval == SH_JMPSUB)