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

Re: [BUG] Another alias-related crash



On Thu, 20 Sep 2018 18:30:03 -0500
dana <dana@xxxxxxx> wrote:
>   # Crash
>   % alias grep='grep --color=auto'
>   % echo $(( $(echo x | grep . ))
>   zsh: segmentation fault

I'm not getting a crash but valgrind does show a problem.  It suggests
this simple patch fixes it.  The DPUTS is just a paranoid check which
isn't relevant to the crash here; these are all compiled out unless you
have a debug buid.

This code is particularly complicated owing to having to decide between

$(( $(echo stuff) ))

--- mathematical evaluation --- and

$(( $(echo stuff)); more stuff)

--- command substitution with a subshell inside, which as far as I can
see is valid syntax.  Although the alias bug isn't directly related, I
think it shows up here because of the particularly active use of the
input stack while the shell is deciding what's going on.

Would strongly advise NOT doing completion in that sort of code.  The
resulting bus smash of hard to understand bits of the shell could make
the quantum vacuum unstable.  (Sort of "off mass shell".  Physicists'
joke, sort of.)

pws

diff --git a/Src/input.c b/Src/input.c
index 9787dedf6..e9989ffe4 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -555,6 +555,7 @@ inpush(char *str, int flags, Alias inalias)
 	if ((instacktop->alias = inalias))
 	    inalias->inuse = 1;
     } else {
+	instacktop->alias = NULL;
 	/* If we are continuing an alias expansion, record the alias
 	 * expansion in new set of flags (do we need this?)
 	 */
@@ -691,6 +692,7 @@ char *input_hasalias(void)
     {
 	if (!(flags & INP_CONT))
 	    break;
+	DPUTS(instackptr == instack, "BUG: continuation at bottom of instack");
 	instackptr--;
 	if (instackptr->alias)
 	    return instackptr->alias->node.nam;



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