[uClinux-dev] Stack overflow in the readdir

Jamie Lokier jamie at shareable.org
Wed Feb 4 08:51:02 EST 2009


Davide Zanni wrote:
> Hi all,
>     I have an application that display the content of an USB key with 
> the function readdir. This work fine but with an USB key the application 
> crash because in the file uClibc/libc/sysdeps/linux/common/getdents.c 
> the compiler try to allocate about 31K of data with the function "alloca 
> (red_nbytes)" and the default stack size is 12K in the thread that use 
> the function. To solve the problem I have increased the stack size of 
> that thread.
> For the other program that use uClibc and the function readdir, like 
> busybox, it's possible that the program will crash. It's possible change 
> the allocation of the memory with the malloc to solve the problem for 
> all the application?

Perhaps this should be sent to the uClibc mailing list instead.

A few places in uClibc have this problem.  I found the regular
expression calls often overflow the stack and crash the app, or worse,
cause strange behaviours.

It's difficult to know how much stack an app should have to avoid
these problems.

In my own programs which use alloca, I use malloc/free pairs instead
when compiling for uClinux:

#ifdef NOMMU
# define tmp_alloc(size) xmalloc(size)
# define tmp_free(ptr)   free(ptr)
#else
# define tmp_alloc(size) alloca(size)
# define tmp_free(ptr)   ((void) 0)
#endif

-- Jamie



More information about the uClinux-dev mailing list