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

Re: Infinite loop in parsing <()?



On Thu, 25 Mar 2010 12:17:48 +0100
Christian Neukirchen <chneukirchen@xxxxxxxxx> wrote:
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
> 
> > On Mar 24,  7:22pm, Christian Neukirchen wrote:
> > }
> > } % cat <(echo foo | sort)
> > } # 100% CPU usage
> >
> > My guess would be that you have an alias for "sort" ...?
> 
> Whoops, right: 
> sort='LC_ALL=C sort'
> 
> % cat <(echo foo | LC_ALL=C sort)
> 
> works in zsh -f, but not with the alias set.

Yes, that's 100% reproducible.  Took a little hunting down.  This is a
local diff since CVS is a bit slow.

--- Src/input.c	2010-01-18 10:17:49.000000000 +0000
+++ ../zsh-debug/zsh/Src/input.c	2010-03-25 12:58:04.000000000 +0000
@@ -195,21 +195,24 @@
 	    return lastc;
 	}
 
-	/* If the next element down the input stack is a continuation of
-	 * this, use it.
-	 */ 
-	if (inbufflags & INP_CONT) {
-	    inpoptop();
-	    continue;
-	}
 	/*
-	 * Otherwise, see if we have reached the end of input
+	 * See if we have reached the end of input
 	 * (due to an error, or to reading from a single string).
+	 * Check the remaining characters left, since if there aren't
+	 * any we don't want to pop the stack---it'll mark any aliases
+	 * as not in use before we've finished processing.
 	 */
-	if (strin || errflag) {
+	if (!inbufct && (strin || errflag)) {
 	    lexstop = 1;
 	    return ' ';
 	}
+	/* If the next element down the input stack is a continuation of
+	 * this, use it.
+	 */
+	if (inbufflags & INP_CONT) {
+	    inpoptop();
+	    continue;
+	}
 	/* As a last resort, get some more input */
 	if (inputline())
 	    return ' ';
--- Test/A02alias.ztst	2009-03-03 17:08:12.000000000 +0000
+++ ../zsh-debug/zsh/Test/A02alias.ztst	2010-03-25 13:00:07.000000000 +0000
@@ -36,3 +36,9 @@
 >Without
 >This command has the argument true
 >With
+
+  print -u $ZTST_fd 'This test hangs the shell when it fails...'
+  alias sort='LC_ALL=C sort'
+  cat <(echo foo | sort)
+0:Alias expansion works at the end of parsed strings
+>foo

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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