summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-17 00:47:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-17 00:47:19 +0000
commit71120953d75abb6b7203850799b869347b805b82 (patch)
tree1c6088c986d69a953b170231518d6a655f161da8 /dir.c
parente75fbfdacbf7d064dfcd908e222418a2da3869a5 (diff)
dir.c: fix glob with base when no DT_UNKNOWN
* dir.c (do_stat, do_lstat): need the length of the base path for fstatat() when fd is valid. * dir.c (glob_helper): fix for platforms where DT_UNKNOWN is not available, e.g. Solaris. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/dir.c b/dir.c
index 1670a476ee..8b37ba8143 100644
--- a/dir.c
+++ b/dir.c
@@ -1380,10 +1380,10 @@ typedef struct {
/* System call with warning */
static int
-do_stat(int fd, const char *path, struct stat *pst, int flags, rb_encoding *enc)
+do_stat(int fd, size_t baselen, const char *path, struct stat *pst, int flags, rb_encoding *enc)
{
#if USE_OPENDIR_AT
- int ret = fstatat(fd, path, pst, 0);
+ int ret = fstatat(fd, path + baselen, pst, 0);
#else
int ret = STAT(path, pst);
#endif
@@ -1395,10 +1395,10 @@ do_stat(int fd, const char *path, struct stat *pst, int flags, rb_encoding *enc)
#if defined HAVE_LSTAT || defined lstat || USE_OPENDIR_AT
static int
-do_lstat(int fd, const char *path, struct stat *pst, int flags, rb_encoding *enc)
+do_lstat(int fd, size_t baselen, const char *path, struct stat *pst, int flags, rb_encoding *enc)
{
#if USE_OPENDIR_AT
- int ret = fstatat(fd, path, pst, AT_SYMLINK_NOFOLLOW);
+ int ret = fstatat(fd, path + baselen, pst, AT_SYMLINK_NOFOLLOW);
#else
int ret = lstat(path, pst);
#endif
@@ -2047,7 +2047,7 @@ glob_helper(
if (*base) {
if (match_all && pathtype == path_unknown) {
- if (do_lstat(fd, base, &st, flags, enc) == 0) {
+ if (do_lstat(fd, 0, base, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode);
}
else {
@@ -2055,7 +2055,7 @@ glob_helper(
}
}
if (match_dir && (pathtype == path_unknown || pathtype == path_symlink)) {
- if (do_stat(fd, base, &st, flags, enc) == 0) {
+ if (do_stat(fd, 0, base, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode);
}
else {
@@ -2167,7 +2167,7 @@ glob_helper(
if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1) &&
new_pathtype == path_unknown) {
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
- if (do_lstat(fd, buf, &st, flags, enc) == 0)
+ if (do_lstat(fd, name - buf, buf, &st, flags, enc) == 0)
new_pathtype = IFTODT(st.st_mode);
else
new_pathtype = path_noent;