Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Don't segfault when uniquifying hidden tied arrays
- X-seq: zsh-workers 55021
- From: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] Don't segfault when uniquifying hidden tied arrays
- Date: Thu, 23 Jul 2026 00:29:11 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=q+1IgufWb489u48KM8llzjovKYBQ06hMRsKwUjI3M8k=; fh=vuDAGjptCPc/P1/HEZ3j98yPJEW1XjuEoEAmmwDS/+U=; b=NirCyvVAPJhwcLJK9E5cn8Cn1mF2D6+BcmPx+LnFBF55Mwe328qeeFPV134K18WZDX rhLLX7vo5sxZbFIi8wi0jqSx2NmfRoilJPbcQp/cc+eTXGhwUNtlQPa61wgdrYYbTybS 19Jcs3Ho1y6CTuhUzaRso+iwFDja6YufWrHBxIt3FoUUrY48Tv/X3h4sEG8PBOAquXMo 7h6INIHX0HDLng7zcPIGor/2vpOUAK7KBoThwsJl9bCv1p1mwpz4jrsuB5mlwNlLpM4W kWXzvOvivKgBBlWGlm6g6m4pFNXDwfZWMseFdyY8bIModpeaJb6s5zCeylz3uVZvzxCg i1hA==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1784759363; cv=none; d=google.com; s=arc-20260327; b=nxIlRMueQTV164hgGC7paetOkYyl0+5UIUHJZhE7mb66MR8cthi2uKPHurOv38M2qr EH4RiMC4qfESoPzaWsRZsqYJ3fO2ttS7zrJz+07TrXw71d06ih/QNDiyLaj3D9NEsPAr Avp4AjoMGSvIEX9NQaFm52MRhggv+HJRZaaZ14qzKyBVWyZoQcJIfEJh/2O3LwQc5qYw l3uBieQkySS0UbUVUqwlrb9tuJD0k7Cs0pBN5gxcrCZa4/HXGFWzWVVQWxuqvgjdmUSC vsUuY/ix9ABOoRIWpim6WblHMK/UfU1ZeRrDGdFarnuhT0a73Y1Ec9ofEJ41ZMN6qtmc BRhA==
- Archived-at: <https://zsh.org/workers/55021>
- In-reply-to: <CAH+w=7Z_Y7-5PDZTzssVVyBBtX1X4XQSFr6TLS3EWSkcs+DbWw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchsZEkiDqMzwae6B0NhPG+mTGcSk+snEHjSj6iYwM-TC=Q@mail.gmail.com> <CAH+w=7aoKm=qAt0tMnM+Ls0eF0PvbK_OKqDSM22v38AzgFMxhA@mail.gmail.com> <CAGdYchs4StAndjgG9aY1wTf8OvsaWnaJ5ONxRgr23QN6o3UuLQ@mail.gmail.com> <CAH+w=7Z_Y7-5PDZTzssVVyBBtX1X4XQSFr6TLS3EWSkcs+DbWw@mail.gmail.com>
> While pm->u.data is never NULL, the value assigned to x may be NULL but that's fine, then the code that follows simply does nothing; the function uniqarray immediately returns if its parameter is NULL.
The test case that fails if &nullarray is NOT returned by gsu.a->getfn is
Running test: add array to empty parameter
Strange, I can't reproduce this. My patch was built on top of
workers/54987 but A06assign.zest fails neither with my original patch nor when I rebase it onto HEAD.
With your patch:
Src/zsh -f
% setopt typesettounset
% typeset -T VAR var
% () { typeset -i var; typeset -g -U VAR }
% echo $VAR
% echo $+VAR
0
% () { typeset -i var; typeset -g -U VAR='a:a:b' }
% () { typeset -i var; typeset -g -U VAR='a:a:b'; typeset -p VAR }
zsh: bus error Src/zsh -f
It crashes on "typeset -p" rather than on the assignment itself.
Without your patch, the above does not crash (but your original
example does).
I don't get a bus error but a segmentation fault and it's not caused by the last "typeset -p VAR" but by the "typeset -g -U VAR='a:a:b'" that precedes it. In fact the following is enough to trigger the segmentation fault:
% setopt typesettounset
% typeset -T VAR var
% typeset -U VAR='a:a:b'
% typeset -U VAR='a:a:b'
zsh: segmentation fault
I figured that the issue, or at least one of the issues, was
workers/55020. After rebasing this patch onto that one (see updated patch below), the problem goes away.
Philippe
diff --git a/Src/builtin.c b/Src/builtin.c
index 61d2a2730..4a0eba671 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2253,7 +2253,6 @@ typeset_single(char *cname, char *pname, Param pm, int func,
return NULL;
}
if ((on & PM_UNIQUE) && !(pm->node.flags & PM_READONLY & ~off)) {
- Param apm;
char **x;
if (PM_TYPE(pm->node.flags) == PM_ARRAY) {
x = (*pm->gsu.a->getfn)(pm);
@@ -2264,10 +2263,10 @@ typeset_single(char *cname, char *pname, Param pm, int func,
(*pm->gsu.a->setfn)(pm, x);
} else if (pm->ename && x)
arrfixenv(pm->ename, x);
- } else if (PM_TYPE(pm->node.flags) == PM_SCALAR && pm->ename &&
- (apm =
- (Param) paramtab->getnode(paramtab, pm->ename))) {
- x = (*apm->gsu.a->getfn)(apm);
+ } else if (PM_TYPE(pm->node.flags) == PM_SCALAR && pm->ename) {
+ x = *(pm->node.flags & PM_SPECIAL
+ ? (char ***)pm->u.data
+ : ((struct tieddata *)pm->u.data)->arrptr);
uniqarray(x);
if (x)
arrfixenv(pm->node.nam, x);
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 7bc44dbdc..3bdd36b32 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -329,6 +329,20 @@
>local unique tied array SCALAR
>array local tied SCALAR array
+ typeset -T VAR var=(a b c b a)
+ () {
+ typeset -i var=1
+ typeset -g -U VAR
+ typeset -p VAR var
+ }
+ typeset -p VAR var
+0:Regression test for not segfaulting when uniquifying a hidden tied array
+F:BUG:The inner "typeset -p VAR" should contain the value of the outer "var"
+>typeset -g -UT VAR var=1
+>typeset -i var=1
+>typeset -UT VAR var=( a b c )
+>typeset -aT VAR var=( a b c )
+
typeset -T SCALAR array
typeset +T SCALAR
1:Untying is prohibited
Messages sorted by:
Reverse Date,
Date,
Thread,
Author