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

Re: [PATCH] Don't segfault when uniquifying hidden tied arrays



On Mon, Jul 20, 2026 at 7:55 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Sun, Jul 19, 2026 at 7:28 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> - (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);

Just checking ... apm->gsu.a->getfn can return the static &nullarray
to guarantee the result is never NULL.

Are you confident that pm->u.data is never NULL or a pointer to NULL here?

pm->u.data is never NULL by constructions. Global special tied scalars like PATH are initialized with IPDEF8, which initializes u.data with a pointer to the underlying variable. Similarly, module defined tied scalars, like WATCH, have their u.data initialized with a pointer to the underlying variableUser defined tied scalars initialize u.data with an instance of tieddata whose arrptr points to the u.arr of the tied array.

The function colonarrgetfn used by special tied scalars assumes that u.data contains a non-NULL char***.

The function tiedarrgetfn used by user defined tied scalars assumes that u.data contains a non-NULL struct tieddata * whose arrptr field contains a non-NULL char***.

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.

Philippe



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