[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Segfault after many stackframes
From: |
Chet Ramey |
Subject: |
Re: Segfault after many stackframes |
Date: |
Mon, 13 May 2019 15:31:43 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
On 5/4/19 7:56 AM, Ole Tange wrote:
>> You've obviously overlooked the FUNCNEST variable and its effects,
>
> I tried with FUNCNEST:
>
> $ FUNCNEST=100000000
> $ re() { t=$((t+1)); if [[ $t -gt 8000000 ]]; then echo foo; return;
> fi; re; }; re
> Warning: Program '/bin/bash' crashed.
>
> So even by setting FUNCNEST it still crashes.
Sure, of course. If you set FUNCNEST high enough that the recursion exceeds
your stack size resource limit before that limit is reached, it will crash.
There's no surprise there.
>
> The man page 4.4.19(1) says:
>
> "By default, no limit is imposed on the number of recursive calls."
>
> which I cannot see as being correct. It may not be limited by
> FUNCNEST, but it is clearly limited.
Bash doesn't impose a limit. You (or the system) impose a recursion limit
via the stack size resource limit.
>
>> I am curious about this point. Why do you think bash would exceed some
>> kind of memory resource limit before it exceeds a stack size limit?
>
> I expect bash to behave similar to other interpreted languages by
> either telling me that I have reached the limit of recursion (like
> Zsh/Ksh) or by running out of memory (like Perl). I expect this to
> happen without setting FUNCNEST.
I can't understand why you think this is an answer to that question.
In any event, it would be appropriate for some distribution to set
FUNCNEST in a startup file. There's never going to be a single limit
that satisfies everyone.
> I imagine the segfault happens because we have a pointer outside the
> stack size limit. Maybe just give an error and exit ("out of stack
> space" or similar - preferably also telling me how to raise this limit
> in case this was not an mistake), whenever such a pointer is
> encountered instead of segfaulting? Had I seen that, I would not have
> assumed it was a bug.
If someone would like to incorporate libsigsegv APIs into bash, I'd be
glad to take a look at adding that to the distribution. (I'm not
interested in distributing that library, though.)
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/