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

Re: [BUG] crash when I unset and redefine a function within itself



On Wed, Oct 16, 2024 at 10:56 AM Gilles <gilles.usenet@xxxxxxxxx> wrote:
>
> zsh -c 'foo () { unset -f foo; foo () { echo redefined; }; }; foo'
> [1]    89793 segmentation fault (core dumped)  zsh -c 'foo () { unset -f foo; foo () { echo redefined; }; }; foo'
>
> This works with zsh 5.8.1 on Ubuntu 22.04 and older versions.

This is due to commit ca6f4466e661f185d083e09c55fb93d16e0736cc:

    45131: Make a function that redefines itself preserve its tracedness.

Fix is straightforward; "tracedness" can't be preserved across unfunction:

diff --git a/Src/exec.c b/Src/exec.c
index 8aa7466f5..bc07e8c39 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -5504,7 +5504,8 @@ execfuncdef(Estate state, Eprog redir_prog)
         if (funcstack && funcstack->tp == FS_FUNC &&
             !strcmp(s, funcstack->name)) {
         Shfunc old = ((Shfunc)shfunctab->getnode(shfunctab, s));
-        shf->node.flags |= old->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL);
+        if (old)
+            shf->node.flags |= old->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL);
         }
         shfunctab->addnode(shfunctab, ztrdup(s), shf);
     }




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