mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Error out on 'redirect >foo' inside ${ shared-state comsub; }
The following caused an infinite loop: v=${ exec >/dev/tty; } v=${ redirect >/dev/tty; } Even the original authors didn't figure out how to 'exec >foo' or 'redirect >foo' inside a non-forking command substitution, so they fork it by calling sh_subfork(). If we delete that call, even normal command substitutions enter into that infinite loop. But of course a shared-state comsub can never fork as it would no longer share its state. Without a solution to make this work without forking, an error message is the only sensible thing left to do. src/cmd/ksh93/sh/io.c: sh_redirect(): - If we're redirecting standard output (1), the redirection is permanent as in 'exec'/'redirect' (flag==2), and we're in a subshare, then error out. Resolves: https://github.com/ksh93/ksh/issues/128
This commit is contained in:
parent
e1690f61ff
commit
500757d78b
1 changed files with 7 additions and 2 deletions
|
@ -1126,8 +1126,13 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
{
|
||||
iof=iop->iofile;
|
||||
fn = (iof&IOUFD);
|
||||
if(fn==1 && shp->subshell && !shp->subshare && (flag==2 || isstring))
|
||||
sh_subfork();
|
||||
if(fn==1)
|
||||
{
|
||||
if(shp->subshare && flag==2)
|
||||
errormsg(SH_DICT,ERROR_exit(1),"cannot redirect stdout inside shared-state comsub");
|
||||
if(shp->subshell && (flag==2 || isstring))
|
||||
sh_subfork();
|
||||
}
|
||||
if(shp->redir0 && fn==0 && !(iof&IOMOV))
|
||||
shp->redir0 = 2;
|
||||
io_op[0] = '0'+(iof&IOUFD);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue