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

Segfault copying an emulated function outside of emulation



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;
     }




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