Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: crash with nameref and local argv
- X-seq: zsh-workers 54027
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: crash with nameref and local argv
- Date: Tue, 4 Nov 2025 12:25:56 -0800
- Archived-at: <https://zsh.org/workers/54027>
- In-reply-to: <CAH+w=7YuE2GzH1F9r9Q6WmJxk1puj1M1qmSLsQ76pJ2r+49r4g@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHYJk3Qe7XuGv_B8nFUdHLD4C_kSgaJkS5acAFWTJ2Db_GWoUQ@mail.gmail.com> <CAHYJk3RW-a5_sG4sc4pN-X3=Q1AQ2rZbBsKidWXEBzJps8piZw@mail.gmail.com> <CAH+w=7YuE2GzH1F9r9Q6WmJxk1puj1M1qmSLsQ76pJ2r+49r4g@mail.gmail.com>
On Mon, Nov 3, 2025 at 8:53 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> > On Tue, Jun 10, 2025 at 1:11 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > >
> > > % () { local argv=( $argv ); typeset -nu foo=argv; echo $foo }
>
> You can't make a named reference to the parent's argv
> array, because that doesn't exist "below" its original scope
Brute-force way to fix this follows. If we run into more special
cases it might be worth passing flags to valid_refname().
diff --git a/Src/params.c b/Src/params.c
index 5a0434e40..444630db9 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3239,7 +3239,8 @@ assignsparam(char *s, char *val, int flags)
return NULL;
}
if (*val && (v->pm->node.flags & PM_NAMEREF)) {
- if (!valid_refname(val)) {
+ if (!valid_refname(val) ||
+ ((v->pm->node.flags & PM_UPPER) && !strcmp(val, "argv"))) {
zerr("invalid variable name: %s", val);
zsfree(val);
unqueue_signals();
Messages sorted by:
Reverse Date,
Date,
Thread,
Author