This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
readdir doesn't handle NULL "DIR *" case correctly
- From: "sandeep" <sandeep at codito dot com>
- To: <ecos-discuss at sources dot redhat dot com>
- Date: Fri, 12 Dec 2003 18:05:57 +0530
- Subject: [ECOS] readdir doesn't handle NULL "DIR *" case correctly
- Organization: Codito Technologies Pvt. Ltd.
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