psss / rpms / ksh

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