zsh-workers
 help / color / mirror / code / Atom feed
* Segfault copying an emulated function outside of emulation
@ 2022-06-09 17:29 Matthew Martin
  2022-06-09 20:37 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Martin @ 2022-06-09 17:29 UTC (permalink / raw)
  To: zsh-workers

ahmubashshir on IRC reported the following causes zsh to segfault

    zsh -c 'emulate sh -c "foo(){ :; }"; functions -c foo bar'

This seems to be because bin_functions calls sticky_emulation_dup with
sticky which is NULL outside of emulation. The below patch fixes the
segfault, but I can't claim to be terribly familiar with the code.


diff --git a/Src/builtin.c b/Src/builtin.c
index 1cef7cce8..4a220ccd7 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3304,7 +3304,7 @@ bin_functions(char *name, char **argv, Options ops, int func)
 	if (newsh->redir)
 	    newsh->redir->nref++;
 	if (shf->sticky)
-	    newsh->sticky = sticky_emulation_dup(sticky, 0);
+	    newsh->sticky = sticky_emulation_dup(shf->sticky, 0);
 	shfunctab->addnode(shfunctab, ztrdup(argv[1]), &newsh->node);
 	return 0;
     }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Segfault copying an emulated function outside of emulation
  2022-06-09 17:29 Segfault copying an emulated function outside of emulation Matthew Martin
@ 2022-06-09 20:37 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-06-09 20:37 UTC (permalink / raw)
  To: Zsh hackers list

On Thu, Jun 9, 2022 at 10:30 AM Matthew Martin <phy1729@gmail.com> wrote:
>
> ahmubashshir on IRC reported the following causes zsh to segfault

This looks right to me, so I've merged this with my patch from 50351
and will commit both.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-09 20:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09 17:29 Segfault copying an emulated function outside of emulation Matthew Martin
2022-06-09 20:37 ` Bart Schaefer

Code repositories for project(s) associated with this 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).