zsh-workers
 help / color / mirror / code / Atom feed
* Infinite loop in parsing <()?
@ 2010-03-24 18:22 Christian Neukirchen
  2010-03-25  0:33 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Neukirchen @ 2010-03-24 18:22 UTC (permalink / raw)
  To: zsh-workers

Hi,

% uname -a
Linux zorya 2.6.32-ARCH #1 SMP PREEMPT Tue Feb 23 19:43:46 CET 2010 x86_64 Genuine Intel(R) CPU U4100 @ 1.30GHz GenuineIntel GNU/Linux

% echo $ZSH_VERSION $ZSH_PATCHLEVEL 
4.3.10 1.4705

% cat <(echo foo | sort)
# 100% CPU usage
^C
(gdb) bt
#0  0x00007ffff74290ae in memcpy () from /lib/libc.so.6
#1  0x000000000044f514 in realloc ()
#2  0x000000000044f7a9 in zrealloc ()
#3  0x0000000000465ec4 in ?? ()
#4  0x000000000046713a in ?? ()
#5  0x0000000000467ebe in ?? ()
#6  0x0000000000468033 in ?? ()
#7  0x00000000004680cc in ?? ()
#8  0x000000000046816b in ?? ()
#9  0x0000000000468289 in ?? ()
#10 0x0000000000469634 in parse_list ()
#11 0x00000000004252f1 in parse_string ()
#12 0x00000000004255d6 in ?? ()
#13 0x000000000042b96f in getproc ()
#14 0x0000000000477e2c in ?? ()
#15 0x000000000047c2b5 in prefork ()
#16 0x0000000000426b47 in ?? ()
#17 0x0000000000428ed6 in ?? ()
#18 0x0000000000429286 in ?? ()
#19 0x000000000042a577 in execlist ()
#20 0x000000000042a7e3 in execode ()
#21 0x000000000043ce48 in loop ()
#22 0x000000000043dc8e in zsh_main ()
#23 0x00007ffff73c7b6d in __libc_start_main () from /lib/libc.so.6
#24 0x000000000040d8a9 in _start ()

For mysterious reasons,
% cat <(echo foo)
% cat <(echo foo | uname)
% cat <(echo foo | wc)
all work fine.

-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org


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

* Re: Infinite loop in parsing <()?
  2010-03-24 18:22 Infinite loop in parsing <()? Christian Neukirchen
@ 2010-03-25  0:33 ` Bart Schaefer
  2010-03-25 11:17   ` Christian Neukirchen
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2010-03-25  0:33 UTC (permalink / raw)
  To: Christian Neukirchen, zsh-workers

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" ...?


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

* Re: Infinite loop in parsing <()?
  2010-03-25  0:33 ` Bart Schaefer
@ 2010-03-25 11:17   ` Christian Neukirchen
  2010-03-25 13:06     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Neukirchen @ 2010-03-25 11:17 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

Bart Schaefer <schaefer@brasslantern.com> 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.

sort='LC_ALL=C /usr/bin/sort'

works as a fix for now... but why does the recursive alias make problems
here and not in general?

-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org


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

* Re: Infinite loop in parsing <()?
  2010-03-25 11:17   ` Christian Neukirchen
@ 2010-03-25 13:06     ` Peter Stephenson
  2010-03-25 14:21       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2010-03-25 13:06 UTC (permalink / raw)
  To: zsh-workers

On Thu, 25 Mar 2010 12:17:48 +0100
Christian Neukirchen <chneukirchen@gmail.com> wrote:
> Bart Schaefer <schaefer@brasslantern.com> 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@csr.com>            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


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

* Re: Infinite loop in parsing <()?
  2010-03-25 13:06     ` Peter Stephenson
@ 2010-03-25 14:21       ` Bart Schaefer
  2010-03-25 15:16         ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2010-03-25 14:21 UTC (permalink / raw)
  To: zsh-workers

On Mar 25,  1:06pm, Peter Stephenson wrote:
}
} +  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

Probably not really anything to worry about, but this test will
fail without hanging if there is no "sort" command in the path.


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

* Re: Infinite loop in parsing <()?
  2010-03-25 14:21       ` Bart Schaefer
@ 2010-03-25 15:16         ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2010-03-25 15:16 UTC (permalink / raw)
  To: zsh-workers

On Thu, 25 Mar 2010 07:21:54 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 25,  1:06pm, Peter Stephenson wrote:
> }
> } +  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
> 
> Probably not really anything to worry about, but this test will
> fail without hanging if there is no "sort" command in the path.

I noticed there were no other uses of sort (actually for reasons hinted at
by the LC_ALL=C there, although I seem to remember that wasn't good
enough---it was getting really hairy to get consistent results across
systems) and was wondering about changing it to another cat, which I've now
done; the test still hangs in old shells.

-- 
Peter Stephenson <pws@csr.com>            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


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

end of thread, other threads:[~2010-03-25 16:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-24 18:22 Infinite loop in parsing <()? Christian Neukirchen
2010-03-25  0:33 ` Bart Schaefer
2010-03-25 11:17   ` Christian Neukirchen
2010-03-25 13:06     ` Peter Stephenson
2010-03-25 14:21       ` Bart Schaefer
2010-03-25 15:16         ` Peter Stephenson

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).