From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Fix crash on unset-through-nameref
Date: Sun, 3 Mar 2024 21:37:34 -0800 [thread overview]
Message-ID: <CAH+w=7ayqWoufueuaHiCzjmzgHtv6VV0m7mEXoHn5nGq4pNOzg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 359 bytes --]
On Sun, Mar 3, 2024 at 2:58 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Sun, Mar 3, 2024 at 12:27 PM Stephane Chazelas <stephane@chazelas.org> wrote:
> >
> > It segfaults with zsh -x though
>
> I'll have a look at that later, thanks.
Variation of the same problem reported by Jun T. when unsetting the
array part of a tied pair.
[-- Attachment #2: unset-via-nameref.txt --]
[-- Type: text/plain, Size: 1756 bytes --]
diff --git a/Src/builtin.c b/Src/builtin.c
index 83144677b..b867ea094 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3935,9 +3935,11 @@ bin_unset(char *name, char **argv, Options ops, int func)
int ref = (pm->node.flags & PM_NAMEREF);
if (!(pm = (Param)resolve_nameref(pm, NULL)))
continue;
- if (ref && pm->level < locallevel) {
+ if (ref && pm->level < locallevel &&
+ !(pm->node.flags & PM_READONLY)) {
/* Just mark unset, do not remove from table */
- pm->node.flags |= PM_DECLARED|PM_UNSET;
+ stdunsetfn(pm, 0);
+ pm->node.flags |= PM_DECLARED;
continue;
}
}
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index ff48e2289..5c123f122 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -669,6 +669,31 @@ F:Checking for a bug in zmodload that affects later tests
>typeset -n ref=two
>typeset -n ref=var
+ typeset -g .K01.scalar='RW'
+ typeset -gA .K01.assoc=(x y)
+ typeset -ga .K01.array=(z)
+ typeset -gi .K01.integer=0
+ typeset -gE .K01.double=0.0
+ typeset -gF .K01.float=0.0
+ typeset -gr .K01.readonly='RO'
+ typeset -n gref
+ for gref in ARGC .K01.{scalar,assoc,array,integer,double,float,readonly}
+ do
+ { unset gref } always { TRY_BLOCK_ERROR=0 }
+ done
+ typeset -p .K01.{scalar,assoc,array,integer,double,float,readonly}
+ unset .K01.{scalar,assoc,array,integer,double,float}
+0:unset various types via nameref, including a readonly special
+>typeset -g .K01.scalar
+>typeset -g -A .K01.assoc
+>typeset -g -a .K01.array
+>typeset -g -i .K01.integer
+>typeset -g -E .K01.double
+>typeset -g -F .K01.float
+>typeset -g -r .K01.readonly=RO
+*?*read-only variable: ARGC
+*?*read-only variable: .K01.readonly
+
unset -n ref
unset one
typeset -n ref
next reply other threads:[~2024-03-04 5:38 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 5:37 Bart Schaefer [this message]
2024-03-04 6:29 ` Stephane Chazelas
2024-03-04 8:39 ` Bart Schaefer
2024-03-04 19:34 ` Stephane Chazelas
2024-03-04 19:36 ` Stephane Chazelas
2024-03-04 23:50 ` Bart Schaefer
2024-03-05 8:36 ` Stephane Chazelas
2024-03-04 23:18 ` Bart Schaefer
2024-03-05 8:18 ` Stephane Chazelas
2024-03-05 18:42 ` Bart Schaefer
2024-03-05 19:38 ` Stephane Chazelas
2024-03-05 23:16 ` Bart Schaefer
2024-03-06 18:21 ` Stephane Chazelas
2024-03-06 19:17 ` Bart Schaefer
2024-03-06 19:37 ` Bart Schaefer
2024-03-05 19:48 ` unset, POSIX and the export attribute (Was: [PATCH] Fix crash on unset-through-nameref) Stephane Chazelas
2024-03-05 19:51 ` [PATCH] Fix crash on unset-through-nameref Stephane Chazelas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7ayqWoufueuaHiCzjmzgHtv6VV0m7mEXoHn5nGq4pNOzg@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).