From: Bart Schaefer <schaefer@brasslantern.com>
To: Gilles <gilles.usenet@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: [BUG] crash when I unset and redefine a function within itself
Date: Wed, 16 Oct 2024 12:54:50 -0700 [thread overview]
Message-ID: <CAH+w=7YHrNEQx4aFEdvZ69vJoxr7+KQ4d1nAmkcpFyRupePktQ@mail.gmail.com> (raw)
In-Reply-To: <CAHf9+CvfRwuwAEFLgOqEpjM6bAZtg4r2BgRgr1rZNf-akmJgyg@mail.gmail.com>
On Wed, Oct 16, 2024 at 10:56 AM Gilles <gilles.usenet@gmail.com> 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);
}
prev parent reply other threads:[~2024-10-16 19:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 17:55 Gilles
2024-10-16 19:54 ` Bart Schaefer [this message]
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=7YHrNEQx4aFEdvZ69vJoxr7+KQ4d1nAmkcpFyRupePktQ@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=gilles.usenet@gmail.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).