1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 05:16:05 +01:00

31141: Tighten NO_CLOBBER restrictions on {fd} syntax

to apply only if $fd is exactly an fd and nothing else.
This commit is contained in:
Peter Stephenson 2013-03-10 21:45:04 +00:00
parent 44907223ff
commit fb3ad98f71
3 changed files with 26 additions and 2 deletions

View file

@ -1,3 +1,9 @@
2013-03-10 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 31141: Src/exec.c, Test/A04redirect.ztst: NO_CLOBBER for {fd}
syntax should only apply if $fd is exactly an fd and nothing
else.
2013-03-10 Mikael Magnusson <mikachu@gmail.com>
* 30496: Src/prompt.c: Parse argument to %F and %K as prompt
@ -577,5 +583,5 @@
*****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5816 $
* $Revision: 1.5817 $
*****************************************************

View file

@ -1885,7 +1885,14 @@ checkclobberparam(struct redir *f)
return 0;
}
if (!isset(CLOBBER) && (fd = (int)getintvalue(v)) &&
/*
* We can't clobber the value in the parameter if it's
* already an opened file descriptor --- that means it's a decimal
* integer corresponding to an opened file descriptor,
* not merely an expression that evaluates to a file descriptor.
*/
if (!isset(CLOBBER) && (s = getstrvalue(v)) &&
(fd = (int)zstrtol(s, &s, 10)) >= 0 && !*s &&
fd <= max_zsh_fd && fdtable[fd] == FDT_EXTERNAL) {
zwarn("can't clobber parameter %s containing file descriptor %d",
f->varid, fd);

View file

@ -328,6 +328,17 @@
1q:NO_CLOBBER prevents overwriting parameter with allocated fd
?(eval):4: can't clobber parameter myfd containing file descriptor $myfd
(setopt noclobber
exec {myfd}>logfile2b
print First open >&$myfd
rm -f logfile2b # prevent normal file no_clobberation
myotherfd="${myfd}+0"
exec {myotherfd}>logfile2b
print Overwritten >&$myotherfd)
cat logfile2b
0:NO_CLOBBER doesn't complain about any other expression
>Overwritten
(exec {myfd}>logfile4
echo $myfd
exec {myfd}>&-