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

Re: unbounded recursive call in a shell script crashes zsh



On Tuesday, April 11, 2017 16:01:10 Jérémie Roquet wrote:
> 2017-04-11 15:29 GMT+02:00 Jérémie Roquet <jroquet@xxxxxxxxxxxxx>:
> > 2017-04-11 15:00 GMT+02:00 Kamil Dudka <kdudka@xxxxxxxxxx>:
> >> The following shell script crashes zsh (tested with zsh-5.3.1-90-
g63f086d):
> >>     function foo() {
> >>     
> >>         if true; then
> >>         
> >>             foo
> >>         
> >>         fi
> >>     
> >>     }
> >>     
> >>     foo
> > 
> > That's interesting:
> > 
> > $ zsh -c 'foo() { foo }; foo'
> > foo: maximum nested function level reached
> > 
> > $ zsh -c 'foo() { if true; then foo; fi }; foo'
> > Segmentation fault
> 
> That looks like a stack overflow…
> 
> Doing either of the following fixed the issue for me:
>  - recompile after “./configure --enable-max-function-depth=500”
> (default is 1000);
>  - execute after “ulimit -s 16384” (default for me was 8192).

Thanks!  I can confirm that the error is handled properly after increasing
the limit for stack allocation.

So the difference is caused by the fact that recent versions of zsh are
more hungry on stack, so the stack allocation limit is exceeded before the 
shell call recursion limit is reached.

Kamil

> Best regards,



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