Problem with bug-readdir1

Ian Wienand ianw@gelato.unsw.edu.au
Tue Dec 3 17:19:00 GMT 2002


RE my last patch for IA64 inline syscall support, the only thing that
broke was this test.

In the test the dirent is closed and then attempted to be re-opened.
However, on close the memory is free'd leaving us an invalid pointer.

To fix this I

1. reset the test pointer to null after closing

--- dirent/bug-readdir1.c.old	2002-12-04 12:10:18.000000000 +1100
+++ dirent/bug-readdir1.c	2002-12-04 11:36:09.000000000 +1100
@@ -30,6 +30,8 @@
       exit (1);
     }

+  dirp = NULL ;
+
   ent = readdir (dirp);

   return ent != NULL || errno != EBADF;


2. check for null on entry to readdir, set EBADF and return NULL as
manpage suggests.

--- sysdeps/unix/readdir.c.old	2002-12-04 12:14:36.000000000 +1100
+++ sysdeps/unix/readdir.c	2002-12-04 11:38:29.000000000 +1100
@@ -42,6 +42,12 @@
   DIRENT_TYPE *dp;
   int saved_errno = errno;

+  if ( dirp == NULL )
+    {
+      __set_errno(EBADF);
+      return NULL;
+    }
+
   __libc_lock_lock (dirp->lock);

--- sysdeps/unix/readdir_r.c.old	2002-12-04 12:14:36.000000000 +1100
+++ sysdeps/unix/readdir_r.c	2002-12-04 11:39:02.000000000 +1100
@@ -43,6 +43,12 @@
   size_t reclen;
   const int saved_errno = errno;

+  if ( dirp == NULL )
+    {
+      __set_errno(EBADF);
+      return NULL;
+    }
+
   __libc_lock_lock (dirp->lock);

   do


-i
ianw@gelato.unsw.edu.au



More information about the Libc-alpha mailing list