[Top][All Lists]

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

Re: a recursion bug

From: Bob Proulx
Subject: Re: a recursion bug
Date: Tue, 2 Oct 2012 12:24:23 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

Yuxiang Cao wrote:
> 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.

I disagree.  Mostly because if you change the stack size ulimit then
the example program will recurse more or less.  Therefore it is
definitely a stack limit policy that is limiting the behavior of the
example program and not a bash bug.

  $ ulimit -s

  $ ./deep-stack-trial | wc -l

  $ ulimit -s 4096
  $ ulimit -s

  $ ./deep-stack-trial | wc -l

Now a smaller stack size.  Now if the example test code is run it will
be stopped sooner.

  $ ulimit -s 16384
  bash: ulimit: stack size: cannot modify limit: Operation not permitted

Prevented by operating system policy.  Use a slightly smaller size.

  $ ulimit -s 16000
  $ ulimit -s

  $ ./deep-stack-trial | wc -l

Now a larger stack size.  Now if the example test code is run it will
be stopped later.

It is the operating system stack size policy limit that is stopping
the program.  If you have sufficient permission then you may increase
this value even to "unlimited".

  $ su -
  # ulimit -s unlimited
  # ulimit -s

I would not advise this however.  Those limits are placed there for
the reason of containing unreasonable programs from accidentally
creating unreasonable situations.  Or at least unexpected ones.

Just the same however if this is a limit that you personally disagree
with then it is a limit that you may change on your system.  If you
want you may change your system to allow an unlimited level of
recursion.  Then if your system has the memory resources for it your
program will be able to run to completion.  If your system resources
truly become exhausted then of course the program will still fail to
complete successfully.  But it won't be artifically limited by the
system policy.

Bash here in this context is simply running within the operating
system limits imposed by the policy of the system as reflected in the
stack size limits.


reply via email to

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