Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] NO_EXEC should not exec $NULLCMD



> On 06/02/2023 14:33 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> > On 06/02/2023 12:22 Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
> > Steps to reproduce:
> > % PS1='%# ' zsh -f
> > % zsh -nc ': $( < $1 )'; print $?
> > zsh:1: no such file or directory:
> > 1
> 
> $(<$1) is special syntax to open $1 and insert it on the command line;
> it's nothing to do with $NULLCMD, nor is anything being executed.
> So --- given the way NO_EXEC doesn't have a very detailed specification
> in zsh --- I don't think it's actually violating any designed behaviour
> (that's quite a weak statement in these parts).
> 
> However, it is a reasonable question whether the redirection should
> be taking place here at all, as it doesn't in other cases when
> NO_EXEC is set, even if that's mostly a side effect of where the NO_EXEC
> logic lives, so it's certainly quite confusing.   If not, it shouldn't
> be hard to suppress.

This is probably uncontroversial.

pws

diff --git a/Src/exec.c b/Src/exec.c
index c8eb71b34..3330bbce8 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4678,6 +4678,9 @@ getoutput(char *cmd, int qt)
     if (!prog)
 	return NULL;
 
+    if (!isset(EXECOPT))
+	return newlinklist();
+
     if ((s = simple_redir_name(prog, REDIR_READ))) {
 	/* $(< word) */
 	int stream;
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index d38fbed74..533e08773 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -416,6 +416,9 @@
 1:NO_EXEC does recognize bad substitution syntax
 *?* bad substitution
 
+  (setopt noexec; : $(<nonexistentfile))
+0:NO_EXEC does not attempt to read files in $(<....)
+
   setopt NO_eval_lineno
   eval 'print $LINENO'
   setopt eval_lineno




Messages sorted by: Reverse Date, Date, Thread, Author