[前][次][番号順一覧][スレッド一覧]

ruby-changes:51770

From: nobu <ko1@a...>
Date: Tue, 17 Jul 2018 09:47:25 +0900 (JST)
Subject: [ruby-changes:51770] nobu:r63982 (trunk): dir.c: fix glob with base when no DT_UNKNOWN

nobu	2018-07-17 09:47:19 +0900 (Tue, 17 Jul 2018)

  New Revision: 63982

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63982

  Log:
    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.

  Modified files:
    trunk/dir.c
Index: dir.c
===================================================================
--- dir.c	(revision 63981)
+++ dir.c	(revision 63982)
@@ -1380,10 +1380,10 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/dir.c#L1380
 
 /* 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 https://github.com/ruby/ruby/blob/trunk/dir.c#L1395
 
 #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( https://github.com/ruby/ruby/blob/trunk/dir.c#L2047
 
     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( https://github.com/ruby/ruby/blob/trunk/dir.c#L2055
 	    }
 	}
 	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( https://github.com/ruby/ruby/blob/trunk/dir.c#L2167
 	    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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]