Blame SOURCES/ksh-20120801-trapcom.patch

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