[ECOS] readdir doesn't handle NULL "DIR *" case correctly

sandeep sandeep@codito.com
Fri Dec 12 13:03:00 GMT 2003

Hi nickg,

while trying out romfs test (the rom-image used for the test *didn't contain etc
folder*) it was found that readdir function doesn't handle "readdir(NULL)" call
correctly leading to variety of buggy behaviours later.

static void listdir( char *name, int statp )
    int err;
    DIR *dirp;

    diag_printf("<INFO>: reading directory %s\n",name);

    dirp = opendir( name );
    if( dirp == NULL ) SHOW_RESULT( opendir, -1 );

        struct dirent *entry = readdir( dirp );

        if( entry == NULL )
==== snipped =========

in listdir ("/etc",true) call :  opendir("/etc") correctly returned NULL in
mentioned case. however
the for-loop below that never ended as readdir call never returned NULL.

What about the solution - wherein we check the argument to readdir for NULL in
the beginning itself and handle it elegantly there itself? or would you prefer
this to be done in readdir_r function called by this function?

Also it looks like (io/fileio/current/src/dir.cxx) readdir function is not
thread-safe courtesy "static struct dirent ent" ? am i missing something here?


Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

More information about the Ecos-discuss mailing list