зеркало из https://github.com/github/ruby.git
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
284d746392
Коммит
523bd6737e
23
ChangeLog
23
ChangeLog
|
@ -1,3 +1,26 @@
|
|||
Mon Jun 3 07:15:17 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* vm_insnhelper.c (vm_yield_setup_block_args): partially revert r41019.
|
||||
|
|
33
configure.in
33
configure.in
|
@ -1777,7 +1777,6 @@ AC_CHECK_FUNCS(posix_fadvise)
|
|||
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
|
|||
|
||||
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),
|
||||
|
|
55
dir.c
55
dir.c
|
@ -561,50 +561,10 @@ dir_path(VALUE dir)
|
|||
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)
|
|||
{
|
||||
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)
|
|||
{
|
||||
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(
|
|||
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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче