Bug 172300 - Function/alias recursion makes bash crash (versions 2.05 and 3.0)
Function/alias recursion makes bash crash (versions 2.05 and 3.0)
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: bash (Show other bugs)
3.0
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Tim Waugh
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-11-02 10:09 EST by Vincent Rubiolo
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-01-16 10:30:52 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Shell script which triggers the problem when sourced twice (53 bytes, text/plain)
2005-11-02 10:12 EST, Vincent Rubiolo
no flags Details
Session transcript and stack trace for bash 2.05 (1.76 KB, text/plain)
2005-11-02 10:13 EST, Vincent Rubiolo
no flags Details
Session transcript and stack trace for bash 3 (2.70 KB, text/plain)
2005-11-02 10:14 EST, Vincent Rubiolo
no flags Details

  None (edit)
Description Vincent Rubiolo 2005-11-02 10:09:49 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050920 Firefox/1.0.7

Description of problem:
The attached bash_crash shell defines a recursive function/alias. When the script is sourced once, the 'pwd' command works fine. When the script is sourced twice, the command starts an infinite recursion leading to a shell crash.

I have successfully reproduced the crash on both bash-2.05 and bash-3.0 (one RHEL3 and one RHEL4 machine). The functions on which the crash occurs differs depending on the bash version.

See attached files for script source and two session transcripts with stack traces (bash2 and bash3). The traces were obtained using gdb-6.3 built from source on RHEL3 and native gdb-6.3 on RHEL4. I am aware the trace may not be that useful as I don't have the debug symbols. I would welcome a link to the debug syms package though, as was done on bug#157206.

My search for duplicates showed no similarities to existing, opened bugs. Note that it seems that I don't have enough privileges to consult bug#149103 and bug#147573 os could not check these ones.

Note : the problem seem to happen whatever the command/alias is. I originally encountered it because I want to augment the builtin bash 'cd' command behavior; for that purpose, I define an alias on 'cd' which first does a normal 'cd' and some other processing as well. This works fine unless I source the script containing the alias definition twice, which triggers the problem.


Version-Release number of selected component (if applicable):
bash-2.05b-41.4 and bash-3.0-19.2

How reproducible:
Always

Steps to Reproduce:
1. Start bash
2. Source attached bash_script twice
3. Run the aliased command, here 'pwd'
  

Actual Results:  The shell enters an infinite recursion loop (as the increased CPU charge shows) and eventually crashes.

Expected Results:  A message like 'warning: infinite function/alias recursion' should have been printed _if this is forbidden_.

The other solution (which is more correct to me) would be to have the shell not expand such recursive definitions, as it does for pure aliases (e.g. ls='ls -F'). I tend to think this is what it does when the script is sourced once.

Additional info:

RHEL3 machine :
bash-2.05b$ uname -a
Linux huelgoat 2.4.21-32.0.1.EL #1 Tue May 17 18:01:37 EDT 2005 i686 i686 i386 GNU/Linux
bash-2.05b$ cat /etc/redhat-release
Red Hat Enterprise Linux WS release 3 (Taroon Update 5)
bash-2.05b$ rpm -q bash
bash-2.05b-41.4

RHEL4 machine :
bash-3.00$ uname -a
Linux van-naig 2.6.9-11.ELsmp #1 SMP Fri May 20 18:26:27 EDT 2005 i686 i686 i386 GNU/Linux
bash-3.00$ cat /etc/redhat-release
Red Hat Enterprise Linux WS release 4 (Nahant Update 1)
bash-3.00$ rpm -q bash
bash-3.0-19.2
Comment 1 Vincent Rubiolo 2005-11-02 10:12:21 EST
Created attachment 120640 [details]
Shell script which triggers the problem when sourced twice

The problem occurs whatever the function name/command is. Successfully
reproduced with 'pwd', 'ls' and 'cd' commands.
Comment 2 Vincent Rubiolo 2005-11-02 10:13:42 EST
Created attachment 120641 [details]
Session transcript and stack trace for bash 2.05

Stack trace does not contain all symbols. I would gladly welcome the
bash-debug-info patch though.
Comment 3 Vincent Rubiolo 2005-11-02 10:14:31 EST
Created attachment 120642 [details]
Session transcript and stack trace for bash 3

Trace without full symbols. I welcome the bash-debug-info package though.
Comment 4 Vincent Rubiolo 2005-11-02 10:17:49 EST
Typo on reference to bash-debug-info-package : this is bug#157260
Comment 5 Tim Waugh 2007-01-16 07:47:31 EST
It appears bash-3.2 behaves the same way.  I've asked the GNU bash maintainer
for clarification about the intended behaviour, but my understanding is that
this should recurse infinitely as it is already doing.  Similarly:

hello ()
{
  hello
}

has the same effect.
Comment 6 Vincent Rubiolo 2007-01-16 10:06:48 EST
Glad to see the bug is worked on. 

To me, a crash is definitely a bug. The best way would be for the shell to
detect the infinite recursion and print a message/abort evaluation.

I'll wait for the maintainer's comments about the issue.
Comment 7 Tim Waugh 2007-01-16 10:30:52 EST
In general there is no way for it to do this.  Bash is a programming language,
like any other.  For example, the recursive function in comment #5 is certainly
intended to recurse for as long as the system permits.

So I will close this, because the bash documentation is quite clear about how
aliases behave within functions.

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