Dr. Werner Fink 2011-06-10 17:12:42 +00:00 committed by Git OBS Bridge
parent a12f007593
commit b1f01e92ad
3 changed files with 191 additions and 0 deletions

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Jun 10 19:11:07 CEST 2011 - werner@suse.de
- Avoid redirection in subshell if an eval was used (bnc#697394)
-------------------------------------------------------------------
Wed Jun 8 15:14:46 CEST 2011 - werner@suse.de

View File

@ -20,6 +20,11 @@
Name: ksh
BuildRequires: bind-utils bison flex gdbm-devel glibc-devel ncurses-devel procps psmisc pwdutils zlib-devel
%if %suse_version > 1140
%ifarch ia64
BuildRequires: gcc45
%endif
%endif
%if %suse_version > 1020
BuildRequires: bind-libs libbz2-devel
%endif
@ -75,6 +80,7 @@ Patch20: ksh93-argv0.dif
Patch21: ksh93-export.dif
Patch22: ksh93-eintr.dif
Patch23: ksh93-array.dif
Patch24: ksh93-pipe.dif
%global use_suid_exe 0
%global use_locale 1
%global debug_memleak 0
@ -149,6 +155,7 @@ find share/ -type d -a -empty | xargs -r rm -vrf
%patch21
%patch22
%patch23
%patch24
%build
TMPDIR=$(mktemp -d /tmp/ksh-build.XXXXXX) || exit 1

179
ksh93-pipe.dif Normal file
View File

@ -0,0 +1,179 @@
--- src/cmd/ksh93/include/defs.h
+++ src/cmd/ksh93/include/defs.h 2011-06-10 17:37:22.852426230 +0200
@@ -154,7 +154,7 @@ struct limits
pid_t bckpid; /* background process id */ \
pid_t cpid; \
pid_t pipepid; \
- int32_t ppid; /* parent process id of shell */ \
+ pid_t ppid; /* parent process id of shell */ \
int topfd; \
int sigmax; /* maximum number of signals */ \
int savesig; \
--- src/cmd/ksh93/sh/io.c
+++ src/cmd/ksh93/sh/io.c 2011-06-10 18:13:02.511926423 +0200
@@ -1076,15 +1076,18 @@ int sh_redirect(Shell_t *shp,struct iono
message = e_file;
goto fail;
}
- if(shp->subshell && dupfd==1 && (sfset(sfstdout,0,0)&SF_STRING))
+ if(shp->subshell && dupfd==1)
{
if(sfset(sfstdout,0,0)&SF_STRING)
sh_subtmpfile(shp);
- shp->subdup |= 1<< fn;
+ if(shp->comsub==1)
+ shp->subdup |= 1<< fn;
dupfd = sffileno(sfstdout);
}
else if(shp->sftable[dupfd])
sfsync(shp->sftable[dupfd]);
+ if(dupfd!=1 && fn < 10)
+ shp->subdup &= ~(1<<fn);
}
else if(fd=='-' && fname[1]==0)
{
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2011-06-10 18:09:32.396425650 +0200
@@ -86,10 +86,11 @@ struct funenv
* temp file.
*/
static int subpipe[3] = {-1};
-static int subdup;
+static int subdup,tsetio,usepipe;
static void iousepipe(Shell_t *shp)
{
int i;
+ usepipe++;
fcntl(subpipe[0],F_SETFD,FD_CLOEXEC);
subpipe[2] = fcntl(1,F_DUPFD,10);
shp->fdstatus[subpipe[2]] = shp->fdstatus[1];
@@ -112,6 +113,7 @@ static void iounpipe(Shell_t *shp)
{
int n;
char buff[SF_BUFSIZE];
+ usepipe = 0;
close(1);
fcntl(subpipe[2], F_DUPFD, 1);
shp->fdstatus[1] = shp->fdstatus[subpipe[2]];
@@ -135,6 +137,7 @@ static void iounpipe(Shell_t *shp)
}
sh_close(subpipe[0]);
subpipe[0] = -1;
+ tsetio = 0;
}
/*
@@ -533,8 +536,10 @@ int sh_eval(register Sfio_t *iop, int mo
static Sfio_t *io_save;
volatile int traceon=0, lineno=0;
int binscript=shp->binscript;
+ char comsub = shp->comsub;
io_save = iop; /* preserve correct value across longjmp */
shp->binscript = 0;
+ shp->comsub = 0;
#define SH_TOPFUN 0x8000 /* this is a temporary tksh hack */
if (mode & SH_TOPFUN)
{
@@ -573,6 +578,7 @@ int sh_eval(register Sfio_t *iop, int mo
break;
}
sh_popcontext(&buff);
+ shp->comsub = comsub;
shp->binscript = binscript;
if(traceon)
sh_onoption(SH_XTRACE);
@@ -1245,13 +1251,16 @@ int sh_exec(register const Shnode_t *t,
{
register pid_t parent;
int no_fork,jobid;
- int pipes[2];
+ int pipes[3];
if(shp->subshell)
{
sh_subtmpfile(shp);
- subpipe[0] = -1;
- if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK) && sh_pipe(subpipe)>=0)
- iousepipe(shp);
+ if(!usepipe)
+ {
+ subpipe[0] = -1;
+ if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK) && sh_pipe(subpipe)>=0)
+ iousepipe(shp);
+ }
if((type&(FAMP|TFORK))==(FAMP|TFORK))
sh_subfork();
}
@@ -1291,7 +1300,10 @@ int sh_exec(register const Shnode_t *t,
#endif /* SHOPT_BGX */
nv_getval(RANDNOD);
if(type&FCOOP)
+ {
+ pipes[2] = 0;
coproc_init(shp,pipes);
+ }
#if SHOPT_AMP
if((type&(FAMP|FINT)) == (FAMP|FINT))
parent = sh_ntfork(shp,t,com,&jobid,ntflag);
@@ -1353,6 +1365,8 @@ int sh_exec(register const Shnode_t *t,
shp->pipepid = parent;
else
job_wait(parent);
+ if(usepipe && tsetio && subdup)
+ iounpipe(shp);
if(!sh_isoption(SH_MONITOR))
{
shp->trapnote &= ~SH_SIGIGNORE;
@@ -1496,6 +1510,8 @@ int sh_exec(register const Shnode_t *t,
jmpval = sigsetjmp(buff.buff,0);
if(jmpval==0)
{
+ if(shp->comsub==1)
+ tsetio = 1;
sh_redirect(shp,t->fork.forkio,execflg);
(t->fork.forktre)->tre.tretyp |= t->tre.tretyp&FSHOWME;
sh_exec(t->fork.forktre,flags&~simple);
@@ -1580,14 +1596,22 @@ int sh_exec(register const Shnode_t *t,
* All elements of the pipe are started by the parent.
* The last element executes in current environment
*/
- int pvo[2]; /* old pipe for multi-stage */
- int pvn[2]; /* current set up pipe */
+ int pvo[3]; /* old pipe for multi-stage */
+ int pvn[3]; /* current set up pipe */
int savepipe = pipejob;
int showme = t->tre.tretyp&FSHOWME;
pid_t savepgid = job.curpgid;
job.curpgid = 0;
if(shp->subshell)
+ {
sh_subtmpfile(shp);
+ if(!usepipe)
+ {
+ subpipe[0] = -1;
+ if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK) && sh_pipe(subpipe)>=0)
+ iousepipe(shp);
+ }
+ }
shp->inpipe = pvo;
shp->outpipe = pvn;
pvo[1] = -1;
@@ -2543,7 +2567,10 @@ pid_t _sh_fork(register pid_t parent,int
if(jobid)
*jobid = myjob;
if(shp->comsub==1 && subpipe[0]>=0)
- iounpipe(shp);
+ {
+ if(!tsetio || !subdup)
+ iounpipe(shp);
+ }
return(parent);
}
#if !_std_malloc
@@ -2602,6 +2629,7 @@ pid_t _sh_fork(register pid_t parent,int
if(sig>0)
sh_fault(sig);
sh_sigcheck();
+ usepipe=0;
return(0);
}