[BusyBox] Busybox shell fixes

Erik Andersen andersen at lineo.com
Thu Jul 27 22:19:41 UTC 2000


On Thu Jul 27, 2000 at 10:46:13PM +0200, Robert Kaiser wrote:
> Hi all,
> 
> The current busybox shell has a few bugs regarding piped commands:
> 
> begin testcase-------------------------------------
> BusyBox v0.47pre (2000.07.27-19:32+0000) Built-in shell
> Enter 'help' for a list of built-in commands.
> 
> /home/rob/busybox # dd if=/dev/zero bs=20000 count=1 | dd of=/dev/null bs=100
> count=1
> 1+0 records in
> 1+0 records out
> end testcase--------------------------------------
> 
> 
> At this point, the shell hangs. Not even ^C will work.
> This is because the commandline editing code has disabled ^C
> in the TTY settings. The attached patch "cmdedit-signals.patch"
> enables commandline editing only for the time when the shell
> is reading a command. After applying it, ^C will work,
> but the shell still hangs.
> 
> This is because the code in sh.c:runCommand() keeps one
> of the pipe fds open when forking off the first "dd" child process.
> Therefore, when the second "dd" process terminates after reading
> it's 100 bytes from the pipe, there is still one path open to the pipe
> and thus the first "dd" is not awakened.
> 
> The second attached patch, "shell-close-pipe.patch", fixes this.
> 
> Also, with busybox V0.46, I sometimes got a segmentation fault
> due to a null pointer dereference in sh.c:checkJobs().
> 
> This was ultimately caused by the field prog->isStopped not getting
> initialized to zero (routine sh.c:parseCommand()) in the case of a command
> that reads from a pipe. The chain of events leading from this bug to that
> null pointer in checkJobs() is pretty long, so I'm not describing it here
> (unless somebody really wants to know).
> 
> In the current archive, a sanity check has been added in checkJobs(), so
> that null pointer won't be dereferenced any more. Nevertheless, the ultimate
> reason has not been fixed. The attached patch does this, too.
> 
> Cheers
> 


As you may have noticed, I've been doing a bunch of 
work on the shell at the moment, but this case had 
slipped though the cracks.  Excellent analysis and 
fix, thanks!  Applied,

 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--





More information about the busybox mailing list