zsh-workers
 help / color / mirror / code / Atom feed
* noexec does not detect subscript error
@ 2022-01-26 13:42 gqqnb2005
  2022-01-26 17:32 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: gqqnb2005 @ 2022-01-26 13:42 UTC (permalink / raw)
  To: zsh-workers

$ cat a.sh
a=$argv[
$ zsh -n a.sh
$ zsh a.sh
a.sh:1: invalid subscript

The above z shell commands show my a.sh only has "a=$argv[" which
clearly has a syntax error. Then I use zsh -n (noexec) to check the
syntax, zsh does not report any error.

Can the error be fixed so that the -n (noexec) detects these kinds of
apparent errors?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: noexec does not detect subscript error
  2022-01-26 13:42 noexec does not detect subscript error gqqnb2005
@ 2022-01-26 17:32 ` Bart Schaefer
  2022-01-26 17:40   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2022-01-26 17:32 UTC (permalink / raw)
  To: gqqnb2005; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]

On Wed, Jan 26, 2022 at 5:44 AM gqqnb2005 <gqqnb2005@gmail.com> wrote:

> $ cat a.sh
> a=$argv[
> $ zsh -n a.sh
> $ zsh a.sh
> a.sh:1: invalid subscript
>

This seems specifically to be a problem with assignments:

% zsh -n =(echo ': $argv[')
/tmp/zsh8ZwYOj:1: invalid subscript
% zsh -n =(echo 'a=$argv[')
% zsh -n =(echo ': a=$argv[')
/tmp/zshDn6nSf:1: invalid subscript
% zsh -n =(echo 'typeset a=$argv[')
%

There is no syntax check applied to the right-hand-side of an assignment at
parse time unless it appears to include a process substitution or similar,
that's instead left to happen at run time (which never occurs when noexec
is in effect, obviously).  Outside of an assignment, prefork substitutions
etc. are performed even when noexec is in effect, so the error is caught.

It's not clear what to do in the assignment case, because we don't have a
separate code path that only checks syntax of parameter substitutions
without actually substituting them, and it's probably not appropriate to
invoke substitution in the middle of a parse.  We could do some simple
hacks like looking for unmatched brackets, but even that requires taking
quoting into account, etc.

[-- Attachment #2: Type: text/html, Size: 1842 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: noexec does not detect subscript error
  2022-01-26 17:32 ` Bart Schaefer
@ 2022-01-26 17:40   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2022-01-26 17:40 UTC (permalink / raw)
  To: Zsh hackers list

On Wed, Jan 26, 2022 at 9:32 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> There is no syntax check applied to the right-hand-side of an assignment at parse time unless it appears to include a process substitution or similar

Line 1876 and foregoing in Src/parse.c in the current git head, I
should have mentioned.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-26 17:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 13:42 noexec does not detect subscript error gqqnb2005
2022-01-26 17:32 ` Bart Schaefer
2022-01-26 17:40   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).