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
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.
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.
Created attachment 120642 [details] Session transcript and stack trace for bash 3 Trace without full symbols. I welcome the bash-debug-info package though.
Typo on reference to bash-debug-info-package : this is bug#157260
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.
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.
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.