This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

readdir doesn't handle NULL "DIR *" case correctly


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.

romfs/tests/fileio1.c:
--------------------
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 );

    for(;;)
    {
        struct dirent *entry = readdir( dirp );

        if( entry == NULL )
            break;
==== 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?

peace
sandeep


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]