ruby-changes:28990
From: kosaki <ko1@a...>
Date: Mon, 3 Jun 2013 07:38:21 +0900 (JST)
Subject: [ruby-changes:28990] kosaki:r41042 (trunk): * configure.in: removes AC_CHECK_FUNCS(readdir_r). readdir_r()
kosaki 2013-06-03 07:38:11 +0900 (Mon, 03 Jun 2013) New Revision: 41042 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41042 Log: * configure.in: removes AC_CHECK_FUNCS(readdir_r). readdir_r() is only used from dir.c and it doesn't need readdir_r(). * configure.in (SIZEOF_STRUCT_DIRENT_TOO_SMALL): remvoed. It is only used for readdir_r. * dir.c: removes NAME_MAX_FOR_STRUCT_DIRENT. It is not right way to detect maximum length of path len. POSIX require to use fpathconf(). IOW, it might have lead to make a vulnerability using stack smashing. Moreover, readdir() works enough for our usage. * dir.c (READDIR): removes an implementation which uses readdir_r() and parenthesize in a macro body correctly. * dir.c (dir_read): removes IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry), it is used only for readdir_r(). * dir.c (dir_each): ditto. * dir.c (glob_helper): ditto. * dir.c (READDIR): removes entry and dp argument. * dir.c (dir_read): adjust for the above change. * dir.c (dir_each): ditto. * dir.c (glob_helper): ditto. Modified files: trunk/ChangeLog trunk/configure.in trunk/dir.c Index: configure.in =================================================================== --- configure.in (revision 41041) +++ configure.in (revision 41042) @@ -1777,7 +1777,6 @@ AC_CHECK_FUNCS(posix_fadvise) https://github.com/ruby/ruby/blob/trunk/configure.in#L1777 AC_CHECK_FUNCS(posix_memalign) AC_CHECK_FUNCS(ppoll) AC_CHECK_FUNCS(pread) -AC_CHECK_FUNCS(readdir_r) AC_CHECK_FUNCS(readlink) AC_CHECK_FUNCS(round) AC_CHECK_FUNCS(seekdir) @@ -2186,38 +2185,6 @@ fi https://github.com/ruby/ruby/blob/trunk/configure.in#L2185 RUBY_CHECK_SIZEOF([struct stat.st_ino], [long "long long"], [], [@%:@include <sys/stat.h>]) -AC_CACHE_CHECK([whether struct dirent.d_name is too small], rb_cv_sizeof_struct_dirent_too_small, - [AC_COMPILE_IFELSE( - [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([ -@%:@if defined _WIN32 -@%:@ error <<<struct direct in win32/dir.h has variable length d_name>>> -@%:@elif defined HAVE_DIRENT_H -@%:@ include <dirent.h> -@%:@elif defined HAVE_DIRECT_H -@%:@ include <direct.h> -@%:@else -@%:@ define dirent direct -@%:@ if HAVE_SYS_NDIR_H -@%:@ include <sys/ndir.h> -@%:@ endif -@%:@ if HAVE_SYS_DIR_H -@%:@ include <sys/dir.h> -@%:@ endif -@%:@ if HAVE_NDIR_H -@%:@ include <ndir.h> -@%:@ endif -@%:@endif -@%:@include <stddef.h> -@%:@define numberof(array) [(int)(sizeof(array) / sizeof((array)[0]))] -struct dirent d; -])], - [offsetof(struct dirent, [d_name[numberof(d.d_name)]]) - offsetof(struct dirent, d_name) < 256])], - [rb_cv_sizeof_struct_dirent_too_small=yes], - [rb_cv_sizeof_struct_dirent_too_small=no])]) -if test "$rb_cv_sizeof_struct_dirent_too_small" = yes; then - AC_DEFINE(SIZEOF_STRUCT_DIRENT_TOO_SMALL, 1) -fi - if test "$ac_cv_func_sysconf" = yes; then AC_DEFUN([RUBY_CHECK_SYSCONF], [dnl AC_CACHE_CHECK([whether _SC_$1 is supported], rb_cv_have_sc_[]m4_tolower($1), Index: ChangeLog =================================================================== --- ChangeLog (revision 41041) +++ ChangeLog (revision 41042) @@ -1,3 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jun 3 07:15:17 2013 KOSAKI Motohiro <kosaki.motohiro@g...> + + * configure.in: removes AC_CHECK_FUNCS(readdir_r). readdir_r() + is only used from dir.c and it doesn't need readdir_r(). + * configure.in (SIZEOF_STRUCT_DIRENT_TOO_SMALL): remvoed. It is + only used for readdir_r. + * dir.c: removes NAME_MAX_FOR_STRUCT_DIRENT. It is not right way + to detect maximum length of path len. POSIX require to use + fpathconf(). IOW, it might have lead to make a vulnerability + using stack smashing. Moreover, readdir() works enough for our + usage. + * dir.c (READDIR): removes an implementation which uses + readdir_r() and parenthesize in a macro body correctly. + * dir.c (dir_read): removes IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT + entry), it is used only for readdir_r(). + * dir.c (dir_each): ditto. + * dir.c (glob_helper): ditto. + + * dir.c (READDIR): removes entry and dp argument. + * dir.c (dir_read): adjust for the above change. + * dir.c (dir_each): ditto. + * dir.c (glob_helper): ditto. + Mon Jun 3 03:40:29 2013 NARUSE, Yui <naruse@r...> * vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019. Index: dir.c =================================================================== --- dir.c (revision 41041) +++ dir.c (revision 41042) @@ -561,50 +561,10 @@ dir_path(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L561 return rb_str_dup(dirp->path); } -#if defined HAVE_READDIR_R -# define READDIR(dir, enc, entry, dp) (readdir_r((dir), (entry), &(dp)) == 0 && (dp) != 0) -#elif defined _WIN32 -# define READDIR(dir, enc, entry, dp) (((dp) = rb_w32_readdir((dir), (enc))) != 0) +#if defined _WIN32 +# define READDIR(dir, enc) rb_w32_readdir((dir), (enc)) #else -# define READDIR(dir, enc, entry, dp) (((dp) = readdir(dir)) != 0) -#endif -#if defined HAVE_READDIR_R -# define IF_HAVE_READDIR_R(something) something -#else -# define IF_HAVE_READDIR_R(something) /* nothing */ -#endif - -#if defined SIZEOF_STRUCT_DIRENT_TOO_SMALL -# include <limits.h> -# define NAME_MAX_FOR_STRUCT_DIRENT 255 -# if defined NAME_MAX -# if NAME_MAX_FOR_STRUCT_DIRENT < NAME_MAX -# undef NAME_MAX_FOR_STRUCT_DIRENT -# define NAME_MAX_FOR_STRUCT_DIRENT NAME_MAX -# endif -# endif -# if defined _POSIX_NAME_MAX -# if NAME_MAX_FOR_STRUCT_DIRENT < _POSIX_NAME_MAX -# undef NAME_MAX_FOR_STRUCT_DIRENT -# define NAME_MAX_FOR_STRUCT_DIRENT _POSIX_NAME_MAX -# endif -# endif -# if defined _XOPEN_NAME_MAX -# if NAME_MAX_FOR_STRUCT_DIRENT < _XOPEN_NAME_MAX -# undef NAME_MAX_FOR_STRUCT_DIRENT -# define NAME_MAX_FOR_STRUCT_DIRENT _XOPEN_NAME_MAX -# endif -# endif -# define DEFINE_STRUCT_DIRENT \ - union { \ - struct dirent dirent; \ - char dummy[offsetof(struct dirent, d_name) + \ - NAME_MAX_FOR_STRUCT_DIRENT + 1]; \ - } -# define STRUCT_DIRENT(entry) ((entry).dirent) -#else -# define DEFINE_STRUCT_DIRENT struct dirent -# define STRUCT_DIRENT(entry) (entry) +# define READDIR(dir, enc) readdir((dir)) #endif /* @@ -624,11 +584,10 @@ dir_read(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L584 { struct dir_data *dirp; struct dirent *dp; - IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry); GetDIR(dir, dirp); errno = 0; - if (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) { + if ((dp = READDIR(dirp->dir, dirp->enc)) != NULL) { return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc); } else { @@ -662,14 +621,13 @@ dir_each(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L621 { struct dir_data *dirp; struct dirent *dp; - IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry); IF_HAVE_HFS(int hfs_p); RETURN_ENUMERATOR(dir, 0, 0); GetDIR(dir, dirp); rewinddir(dirp->dir); IF_HAVE_HFS(hfs_p = !NIL_P(dirp->path) && is_hfs(RSTRING_PTR(dirp->path))); - while (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) { + while ((dp = READDIR(dirp->dir, dirp->enc)) != NULL) { const char *name = dp->d_name; size_t namlen = NAMLEN(dp); VALUE path; @@ -1440,13 +1398,12 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1398 if (magical || recursive) { struct dirent *dp; DIR *dirp; - IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry); IF_HAVE_HFS(int hfs_p); dirp = do_opendir(*path ? path : ".", flags, enc); if (dirp == NULL) return 0; IF_HAVE_HFS(hfs_p = is_hfs(*path ? path : ".")); - while (READDIR(dirp, enc, &STRUCT_DIRENT(entry), dp)) { + while ((dp = READDIR(dirp, enc)) != NULL) { char *buf; enum answer new_isdir = UNKNOWN; const char *name; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/