bug-bash
[Top][All Lists]
Advanced

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

Bash does not read up the whole script which it is currently executing


From: famzah
Subject: Bash does not read up the whole script which it is currently executing
Date: Tue, 04 Aug 2009 10:48:48 +0300

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_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 -Wall
uname output: Linux famzahpc 2.6.28-14-generic #47-Ubuntu SMP Sat Jul 25 
00:28:35 UTC 2009 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 48
Release Status: release

Description:
        First I would like to say that I'm not sure if this is a bug or a 
feature of Bash.
        If it is a feature, please let me know how to turn it off; or better 
make it disabled by default...
        
        The problem is that Bash does not read up the whole script which it is 
currently executing.
        As a result of this, if we update the script file with a newer version 
while it is running, this may lead to unpredicted results.

Repeat-By:
        Detailed instructions can be found at 
http://www.famzah.net/bashbug-script-read/
        
        Here is the proof-of-concept scenario:
        1) The script initial version is "old.sh".
        2) I run the script and it executes some commands which take very long 
time to complete (like some "rsync" which transfers a lot of data).
        3) Meanwhile, I update the script with a newer version "new.sh" which 
is no logically different than the initial one. Just a comment is deleted. Here 
is a diff.
        4) The already running "old.sh" script is supposed to finish up, and 
the next new call to it should execute the new "new.sh" version.
        5) However, we end up in a situation where the script, which we 
replaced and was already running, suddenly totally misbehaves.
        6) In our test scenario, the already running "old.sh" script deletes 
our "/home" directory which must never happen, having the Bash scripts' source 
code in mind.

Fix:
        Detailed information can be found at 
http://www.famzah.net/bashbug-script-read/
        
        Proposed solution:
        *) Read up the whole script file in memory, so that we have a 
consistent copy of it, regardless of whether we update the script file during 
the execution. This is how ELF binaries are executed on Linux systems.
        or
        *) If the above is not possible due to performance or other reasons, 
please introduce an option so that we can force Bash to copy the script in 
memory before executing it.




reply via email to

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