Bug 433662 - bash segfaults in calling function when it's happening in recursion
bash segfaults in calling function when it's happening in recursion
Status: CLOSED UPSTREAM
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash (Show other bugs)
5.2
All Linux
low Severity high
: rc
: ---
Assigned To: Tomas Janousek
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-20 13:28 EST by Michal Nowak
Modified: 2013-03-07 21:03 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-03-13 15:29:36 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
testcase causing bash to crash (66 bytes, text/plain)
2008-02-20 13:28 EST, Michal Nowak
no flags Details

  None (edit)
Description Michal Nowak 2008-02-20 13:28:36 EST
Description of problem:

When in bash script is function which calls itself repeatedly (recursion) it
causes bash to crash.

Version-Release number of selected component (if applicable):
bash-3.1-16.1

How reproducible:
always

Steps to Reproduce:
1. sh bash-kill.sh
  
Actual results:

dhcp-lab-198 mounting # time sh bash-kill.sh 
Segmentation fault

real    0m8.122s
user    0m8.005s
sys     0m0.088s


Expected results:
dhcp-lab-198 mounting # time sh bash-kill.sh 

+ as a bonus 100 % CPU usage forever
Comment 1 Michal Nowak 2008-02-20 13:28:36 EST
Created attachment 295437 [details]
testcase causing bash to crash
Comment 2 Tomas Janousek 2008-03-05 09:39:49 EST
Well, that's what unbounded recursion does in C as well. ksh solves this by
limiting the recursion depth (to something like 4096, which is not many).

We could limit it as well, but that won't give the results you expect. To get
that, bash would have to support tail recursion, and I guess that would be quite
an overkill for a shell.
Comment 3 Michal Nowak 2008-03-05 17:14:11 EST
Limiting it to some random number seems to me dumb, I don't see any number being
the Right One. User defined MAX_RECURSION=Int seems to me bad for debugging in
general.

The saner solution seems to me mentioned tail recursion.

When there's no agreement in upstream on expected behavior you can always close
it with note in docs that "this case does not have expected result", but that's
kinda coward, but viable.
Comment 5 Michal Nowak 2008-03-09 15:25:38 EDT
> http://lists.gnu.org/archive/html/bug-bash/2008-03/msg00005.html
> 
> ...including libsigsegv as an option for making stack overflow detection
> result in nicer output than a crash.

What about this? It's in Fedora.
Comment 6 Tomas Janousek 2008-03-13 15:29:36 EDT
Well, we don't want to diverge from upstream, so I'll leave this up to them.

Note You need to log in before you can comment on or make changes to this bug.