This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


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

Re: PATCH: fix buffer overrun in natFile.cc




On Wed, 30 May 2001, Bryce McKinlay wrote:
> Anyhow, can we get away with a stack allocation (ie char[sizeof(...)
> + NAME_MAX +1];) instead of the malloc?

Yes.

> Shouldn't NAME_MAX always be available, at least wherever readdir_r is?

No.  At least not on Solaris 7.  I suspect the value of _PC_NAME_MAX isn't
constant but depends on the VFS.

> For simplicity it might be worth dropping the _JV_POSIX_THREADS test and just
> using HAVE_READDIR_R.

Agreed.  Here is a new patch.  I removed get_entry since it seems a little
cleaner without.  Again I tested on sparc-solaris and alpha-linux:


2001-05-29  Jeff Sturm  <jsturm@one-point.com>

	* natFile.cc (get_entry): Removed functions.
	(performList): Call readdir, or readdir_r if HAVE_READDIR_R
	defined.  Allocate enough storage for d_name if using readdir_r.

===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFile.cc,v
retrieving revision 1.7.4.3
diff -u -p -r1.7.4.3 natFile.cc
--- natFile.cc	2001/04/30 23:07:43	1.7.4.3
+++ natFile.cc	2001/05/31 03:44:30
@@ -130,29 +130,6 @@ java::io::File::isAbsolute (void)
   return path->charAt(0) == '/';
 }
 
-#ifdef HAVE_DIRENT_H
-#if defined(__JV_POSIX_THREADS__) && defined(HAVE_READDIR_R)
-
-static struct dirent *
-get_entry (DIR *dir, struct dirent *e)
-{
-  struct dirent *r;
-  if (readdir_r (dir, e, &r) || r == NULL)
-    return NULL;
-  return e;
-}
-
-#else /* defined(__JV_POSIX_THREADS__) && defined(HAVE_READDIR_R) */
-
-static struct dirent *
-get_entry (DIR *dir, struct dirent *)
-{
-  return readdir (dir);
-}
-
-#endif /* defined(__JV_POSIX_THREADS__) && defined(HAVE_READDIR_R) */
-#endif /* HAVE_DIRENT_H */
-
 jobjectArray
 java::io::File::performList (java::io::FilenameFilter *filter, 
 			     java::io::FileFilter *fileFilter, 
@@ -168,9 +145,16 @@ java::io::File::performList (java::io::F
   if (! dir)
     return NULL;
 
+
   java::util::ArrayList *list = new java::util::ArrayList ();
-  struct dirent *d, d2;
-  while ((d = get_entry (dir, &d2)) != NULL)
+  struct dirent *d;
+#ifdef HAVE_READDIR_R
+  int name_max = pathconf (buf, _PC_NAME_MAX);
+  char dbuf[sizeof (struct dirent) + name_max + 1];
+  while (readdir_r (dir, (struct dirent *) dbuf, &d) == 0 && d != NULL)
+#else /* HAVE_READDIR_R */
+  while ((d = readdir (dir)) != NULL)
+#endif /* HAVE_READDIR_R */
     {
       // Omit "." and "..".
       if (d->d_name[0] == '.'


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