From 27c494762b76f95a10f15095993fe37f6562a222 Mon Sep 17 00:00:00 2001 From: kakaroto Date: Sun, 18 Sep 2011 21:56:54 +0000 Subject: [PATCH] Eina: Always use fpathconfig and never assume NAME_MAX is defined git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@63460 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/eina_file.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/lib/eina_file.c b/src/lib/eina_file.c index a2fedd1..dde64f4 100644 --- a/src/lib/eina_file.c +++ b/src/lib/eina_file.c @@ -49,12 +49,6 @@ void *alloca (size_t); #define PATH_DELIM '/' -#ifdef __sun -# ifndef NAME_MAX -# define NAME_MAX 255 -# endif -#endif - #include "eina_config.h" #include "eina_private.h" @@ -153,11 +147,10 @@ static int _eina_file_log_dom = -1; * The code and description of the issue can be found at : * http://womble.decadent.org.uk/readdir_r-advisory.html */ -static size_t -_eina_dirent_buffer_size(DIR *dirp) +static long +_eina_name_max(DIR *dirp) { long name_max; - size_t name_end; #if defined(HAVE_FPATHCONF) && defined(HAVE_DIRFD) && defined(_PC_NAME_MAX) name_max = fpathconf(dirfd(dirp), _PC_NAME_MAX); @@ -182,6 +175,16 @@ _eina_dirent_buffer_size(DIR *dirp) # endif # endif #endif + + return name_max; +} + +static size_t +_eina_dirent_buffer_size(DIR *dirp) +{ + long name_max = _eina_name_max(dirp); + size_t name_end; + name_end = (size_t) offsetof(struct dirent, d_name) + name_max + 1; return (name_end > sizeof (struct dirent) ? name_end : sizeof (struct dirent)); @@ -647,9 +650,6 @@ eina_file_direct_ls(const char *dir) if (length < 1) return NULL; - if (length + NAME_MAX + 2 >= EINA_PATH_MAX) - return NULL; - it = calloc(1, sizeof(Eina_File_Direct_Iterator) + length); if (!it) return NULL; @@ -663,6 +663,12 @@ eina_file_direct_ls(const char *dir) return NULL; } + if (length + _eina_name_max(it->dirp) + 2 >= EINA_PATH_MAX) + { + _eina_file_direct_ls_iterator_free(it); + return NULL; + } + memcpy(it->dir, dir, length + 1); it->length = length; @@ -696,9 +702,6 @@ eina_file_stat_ls(const char *dir) if (length < 1) return NULL; - if (length + NAME_MAX + 2 >= EINA_PATH_MAX) - return NULL; - it = calloc(1, sizeof(Eina_File_Direct_Iterator) + length); if (!it) return NULL; @@ -712,6 +715,12 @@ eina_file_stat_ls(const char *dir) return NULL; } + if (length + _eina_name_max(it->dirp) + 2 >= EINA_PATH_MAX) + { + _eina_file_direct_ls_iterator_free(it); + return NULL; + } + memcpy(it->dir, dir, length + 1); it->length = length; -- 2.7.4