bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a recursion bug


From: Chet Ramey
Subject: Re: a recursion bug
Date: Fri, 28 Sep 2012 16:23:55 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120907 Thunderbird/15.0.1

On 9/28/12 9:54 AM, Yuxiang Cao wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: i486
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_V$
> uname output: Linux frank-laptop 2.6.32-42-generic #96-Ubuntu SMP Wed Aug 15 
> 18:57:09 UTC 2012 i686 GNU/Linux
> Machine Type: i486-pc-linux-gnu
> 
> Bash Version: 4.1
> Patch Level: 5
> Release Status: release
> 
> Description:
>         segmentation fault occur when I use deep recursive function.
> 
> Repeat-By:
> the following content is my code
>        recursion()
> {
>     if [ $1 -ne 15000 ] ;then
>         echo $1
>         let i=$1+1
>         recursion $i
>     fi
>     exit
> }
> recursion 1
> 
> 
> Fix:
>         I use ulimit -s to find stack size, which is 8192kbytes. Then I use 
> valgrind to record the stack size which give me this information.
> test.sh: xmalloc: ../bash/unwind_prot.c:308: cannot allocate 172 bytes 
> (8359936 bytes allocated)
> So from the above information I think this is not a stack overflow, and that 
> is a real fault in this program.

It's not; deep-enough recursion will eventually exhaust available
resources, no matter their limits, and cause the process to crash.  If
the kernel decides that you can't have any more heap space when malloc
requests it, then that's that.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]