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

ruby-changes:5794

From: shyouhei <ko1@a...>
Date: Sun, 15 Jun 2008 23:02:03 +0900 (JST)
Subject: [ruby-changes:5794] Ruby:r17300 (ruby_1_8_5): merge revision(s) 16420,16454:

shyouhei	2008-06-15 23:01:45 +0900 (Sun, 15 Jun 2008)

  New Revision: 17300

  Modified files:
    branches/ruby_1_8_5/defines.h
    branches/ruby_1_8_5/file.c
    branches/ruby_1_8_5/version.h

  Log:
    merge revision(s) 16420,16454:
    * file.c (file_expand_path): support for alternative data stream
      and ignored trailing garbages of NTFS.
    * file.c (rb_file_s_basename): ditto.
    * file.c (rb_file_s_extname): ditto.
    * lib/webrick/httpservlet/filehandler.rb: should normalize path
      name in path_info to prevent script disclosure vulnerability on
      DOSISH filesystems. (fix: CVE-2008-1891)
      Note: NTFS/FAT filesystem should not be published by the platforms
      other than Windows. Pathname interpretation (including short
      filename) is less than perfect.
    * lib/webrick/httpservlet/abstract.rb
      (WEBrick::HTTPServlet::AbstracServlet#redirect_to_directory_uri):
      should escape the value of Location: header.
    * lib/webrick/httpservlet/cgi_runner.rb: accept interpreter
      command line arguments.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/version.h?r1=17300&r2=17299&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/defines.h?r1=17300&r2=17299&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/file.c?r1=17300&r2=17299&diff_format=u

Index: ruby_1_8_5/version.h
===================================================================
--- ruby_1_8_5/version.h	(revision 17299)
+++ ruby_1_8_5/version.h	(revision 17300)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2008-06-15"
 #define RUBY_VERSION_CODE 185
 #define RUBY_RELEASE_CODE 20080615
-#define RUBY_PATCHLEVEL 208
+#define RUBY_PATCHLEVEL 209
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
Index: ruby_1_8_5/defines.h
===================================================================
--- ruby_1_8_5/defines.h	(revision 17299)
+++ ruby_1_8_5/defines.h	(revision 17300)
@@ -254,6 +254,18 @@
 #define ENV_IGNORECASE
 #endif
 
+#ifndef CASEFOLD_FILESYSTEM
+# if defined DOSISH || defined __VMS
+#   define CASEFOLD_FILESYSTEM 1
+# else
+#   define CASEFOLD_FILESYSTEM 0
+# endif
+#endif
+
+#ifndef DLEXT_MAXLEN
+#define DLEXT_MAXLEN 4
+#endif
+
 #ifndef RUBY_PLATFORM
 #define RUBY_PLATFORM "unknown-unknown"
 #endif
Index: ruby_1_8_5/file.c
===================================================================
--- ruby_1_8_5/file.c	(revision 17299)
+++ ruby_1_8_5/file.c	(revision 17300)
@@ -2309,6 +2309,18 @@
 #define isdirsep(x) ((x) == '/')
 #endif
 
+#if defined _WIN32 || defined __CYGWIN__
+#define USE_NTFS 1
+#else
+#define USE_NTFS 0
+#endif
+
+#if USE_NTFS
+#define istrailinggabage(x) ((x) == '.' || (x) == ' ')
+#else
+#define istrailinggabage(x) 0
+#endif
+
 #ifndef CharNext		/* defined as CharNext[AW] on Windows. */
 # if defined(DJGPP)
 #   define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
@@ -2482,6 +2494,30 @@
 }
 #endif
 
+#if USE_NTFS
+static char *
+ntfs_tail(const char *path)
+{
+    while (*path && *path != ':') {
+	if (istrailinggabage(*path)) {
+	    const char *last = path++;
+	    while (istrailinggabage(*path)) path++;
+	    if (!*path || *path == ':') return (char *)last;
+	}
+	else if (isdirsep(*path)) {
+	    const char *last = path++;
+	    while (isdirsep(*path)) path++;
+	    if (!*path) return (char *)last;
+	    if (*path == ':') path++;
+	}
+	else {
+	    path = CharNext(path);
+	}
+    }
+    return (char *)path;
+}
+#endif
+
 #define BUFCHECK(cond) do {\
     long bdiff = p - buf;\
     while (cond) {\
@@ -2728,23 +2764,17 @@
     if (p == skiproot(buf) - 1) p++;
     buflen = p - buf;
 
-    RSTRING(result)->len = buflen;
+#if USE_NTFS
     *p = '\0';
-#if USE_NTFS
-    if (1 &&
-#ifdef __CYGWIN__
-	!(buf[0] == '/' && !buf[1]) &&
-#endif
-	!strpbrk(b = buf, "*?")) {
+    if (!strpbrk(b = buf, "*?")) {
 	size_t len;
 	WIN32_FIND_DATA wfd;
 #ifdef __CYGWIN__
-	int lnk_added = 0, is_symlink = 0;
+	int lnk_added = 0;
 	struct stat st;
 	char w32buf[MAXPATHLEN], sep = 0;
 	p = 0;
 	if (lstat(buf, &st) == 0 && S_ISLNK(st.st_mode)) {
-	    is_symlink = 1;
 	    p = strrdirsep(buf);
 	    if (!p) p = skipprefix(buf);
 	    if (p) {
@@ -2757,7 +2787,8 @@
 	}
 	if (p) *p = sep;
 	else p = buf;
-	if (is_symlink && b == w32buf) {
+	if (b == w32buf) {
+	    strlcat(w32buf, p, sizeof(w32buf));
 	    len = strlen(p);
 	    if (len > 4 && strcasecmp(p + len - 4, ".lnk") != 0) {
 		lnk_added = 1;
@@ -2785,6 +2816,8 @@
 #endif
 
     if (tainted) OBJ_TAINT(result);
+    RSTRING(result)->len = buflen;
+    RSTRING(result)->ptr[buflen] = '\0';
     return result;
 }
 
@@ -2847,7 +2880,12 @@
     }
     if (l1 < l2) return l1;
 
-    if (strncmp(p+l1-l2, e, l2) == 0) {
+#if CASEFOLD_FILESYSTEM
+#define fncomp strncasecmp
+#else
+#define fncomp strncmp
+#endif
+    if (fncomp(p+l1-l2, e, l2) == 0) {
 	return l1-l2;
     }
     return 0;
@@ -2926,7 +2964,7 @@
 	if (NIL_P(fext) || !(f = rmext(p, n, StringValueCStr(fext)))) {
 	    f = n;
 	}
-	if (f == RSTRING(fname)->len) return fname;
+        if (f == RSTRING(fname)->len) return fname;
     }
     basename = rb_str_new(p, f);
     OBJ_INFECT(basename, fname);
@@ -3009,7 +3047,7 @@
     if (!p)
 	p = name;
     else
-	name = ++p;
+	p++;
 
     e = 0;
     while (*p) {
@@ -3039,7 +3077,7 @@
 	    break;
 	p = CharNext(p);
     }
-    if (!e || e == name || e+1 == p)	/* no dot, or the only dot is first or end? */
+    if (!e || e+1 == p)	/* no dot, or the only dot is first or end? */
 	return rb_str_new(0, 0);
     extname = rb_str_new(e, p - e);	/* keep the dot, too! */
     OBJ_INFECT(extname, fname);

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

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