mysterious segfault with busybox 1.13.0 ash

Timo Teräs timo.teras at iki.fi
Fri Nov 21 08:54:01 UTC 2008


Natanael Copa wrote:
> On Thu, 2008-11-20 at 23:42 +0100, Cristian Ionescu-Idbohrn wrote:
>> On Thu, 20 Nov 2008, Bernhard Reutner-Fischer wrote:
>>
>>> On Wed, Nov 19, 2008 at 09:30:27PM +0100, Natanael Copa wrote:
>>>> On Wed, 2008-11-19 at 21:17 +0100, Natanael Copa wrote:
>>>>> shorter testcase:
>>>>>
>>>>> ash -c "foo() { ! false && echo foo; }; foo"
>>> Works for me on trunk (on a debian box)..
>> Doesn't work for me :(  I get something else:
>>
>>   ash: memory exhausted
> 
> there you got it.
> 
> yesterday i reproduced the problem at home on 64 bit ubuntu and 32 bit
> arch linux. IIRC arch uses a (very close to vanilla) gcc-4.3.2. 
> 
> It seems like comand line editing needs to be turned on.
> 
> I'm still not sure the bug is really in busybox, since things seems to
> work with -O0.

Looks like ash was broken in commit r23583 where the node type defines
were changed, but related arrays were not updated. Especially the node
size table which affects size calculations was left out, thus all kind
of funny things such as memory corruption can happen.

Please try the below patch:

Index: shell/ash.c
===================================================================
--- shell/ash.c	(revision 24107)
+++ shell/ash.c	(working copy)
@@ -7556,7 +7556,7 @@
 #define EV_TESTED 02            /* exit status is checked; ignore -e flag */
 #define EV_BACKCMD 04           /* command executing within back quotes */
 
-static const short nodesize[26] = {
+static const short nodesize[27] = {
 	SHELL_ALIGN(sizeof(struct ncmd)),
 	SHELL_ALIGN(sizeof(struct npipe)),
 	SHELL_ALIGN(sizeof(struct nredir)),
@@ -7578,6 +7578,7 @@
 	SHELL_ALIGN(sizeof(struct nfile)),
 	SHELL_ALIGN(sizeof(struct nfile)),
 	SHELL_ALIGN(sizeof(struct nfile)),
+	SHELL_ALIGN(sizeof(struct nfile)),
 	SHELL_ALIGN(sizeof(struct ndup)),
 	SHELL_ALIGN(sizeof(struct ndup)),
 	SHELL_ALIGN(sizeof(struct nhere)),


Cheers,
  Timo



More information about the busybox mailing list