apr-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60191] libapr computes incorrect size for dirent structure
Date Tue, 04 Oct 2016 21:20:50 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60191

--- Comment #5 from Yann Ylavic <ylavic.dev@gmail.com> ---
Since dname_size is constant it can/will be optimized out at compile time too.
The issue is that my version (and Bill's) over allocate memory by using
PATH_MAX instead NAME_MAX, so we could possibly go for something like:

Index: file_io/unix/dir.c
===================================================================
--- file_io/unix/dir.c    (revision 1762122)
+++ file_io/unix/dir.c    (working copy)
@@ -76,9 +76,15 @@ apr_status_t apr_dir_open(apr_dir_t **new, const c
      * platforms (e.g., Solaris 8 for Intel), d_name is declared as a
      * one-byte array.  Note: gcc evaluates this at compile time.
      */
+#if defined(NAME_MAX) && NAME_MAX > 255
+#define DIRENT_NAME_MAX NAME_MAX
+#else
+#define DIRENT_NAME_MAX 255
+#endif
     apr_size_t dirent_size = 
         sizeof(*(*new)->entry) +
-        (sizeof((*new)->entry->d_name) > 1 ? 0 : 255);
+        (sizeof((*new)->entry->d_name) > DIRENT_NAME_MAX ? 0
+         : DIRENT_NAME_MAX + 1 - sizeof((*new)->entry->d_name));
     DIR *dir = opendir(dirname);

     if (!dir) {
_


The best we could do would be to use fpathconf() like proposed in the
dirent_buf_size() function from
https://womble.decadent.org.uk/readdir_r-advisory.html (there may be some
platforms supporting file names longer than NAME_MAX, but with a lower
sizeof(d_name)...).
This is not compile time though, but we are supposedly not in a fast path when
using opendir()/readdir() :)

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


Mime
View raw message