Skip to content

Commit 52649a3

Browse files
committed
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@17300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 98e63de commit 52649a3

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

defines.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ __attribute__ ((noinline))
254254
#define ENV_IGNORECASE
255255
#endif
256256

257+
#ifndef CASEFOLD_FILESYSTEM
258+
# if defined DOSISH || defined __VMS
259+
# define CASEFOLD_FILESYSTEM 1
260+
# else
261+
# define CASEFOLD_FILESYSTEM 0
262+
# endif
263+
#endif
264+
265+
#ifndef DLEXT_MAXLEN
266+
#define DLEXT_MAXLEN 4
267+
#endif
268+
257269
#ifndef RUBY_PLATFORM
258270
#define RUBY_PLATFORM "unknown-unknown"
259271
#endif

file.c

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,18 @@ rb_file_s_umask(argc, argv)
23092309
#define isdirsep(x) ((x) == '/')
23102310
#endif
23112311

2312+
#if defined _WIN32 || defined __CYGWIN__
2313+
#define USE_NTFS 1
2314+
#else
2315+
#define USE_NTFS 0
2316+
#endif
2317+
2318+
#if USE_NTFS
2319+
#define istrailinggabage(x) ((x) == '.' || (x) == ' ')
2320+
#else
2321+
#define istrailinggabage(x) 0
2322+
#endif
2323+
23122324
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
23132325
# if defined(DJGPP)
23142326
# define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
@@ -2482,6 +2494,30 @@ ntfs_tail(const char *path)
24822494
}
24832495
#endif
24842496

2497+
#if USE_NTFS
2498+
static char *
2499+
ntfs_tail(const char *path)
2500+
{
2501+
while (*path && *path != ':') {
2502+
if (istrailinggabage(*path)) {
2503+
const char *last = path++;
2504+
while (istrailinggabage(*path)) path++;
2505+
if (!*path || *path == ':') return (char *)last;
2506+
}
2507+
else if (isdirsep(*path)) {
2508+
const char *last = path++;
2509+
while (isdirsep(*path)) path++;
2510+
if (!*path) return (char *)last;
2511+
if (*path == ':') path++;
2512+
}
2513+
else {
2514+
path = CharNext(path);
2515+
}
2516+
}
2517+
return (char *)path;
2518+
}
2519+
#endif
2520+
24852521
#define BUFCHECK(cond) do {\
24862522
long bdiff = p - buf;\
24872523
while (cond) {\
@@ -2728,23 +2764,17 @@ file_expand_path(fname, dname, result)
27282764
if (p == skiproot(buf) - 1) p++;
27292765
buflen = p - buf;
27302766

2731-
RSTRING(result)->len = buflen;
2732-
*p = '\0';
27332767
#if USE_NTFS
2734-
if (1 &&
2735-
#ifdef __CYGWIN__
2736-
!(buf[0] == '/' && !buf[1]) &&
2737-
#endif
2738-
!strpbrk(b = buf, "*?")) {
2768+
*p = '\0';
2769+
if (!strpbrk(b = buf, "*?")) {
27392770
size_t len;
27402771
WIN32_FIND_DATA wfd;
27412772
#ifdef __CYGWIN__
2742-
int lnk_added = 0, is_symlink = 0;
2773+
int lnk_added = 0;
27432774
struct stat st;
27442775
char w32buf[MAXPATHLEN], sep = 0;
27452776
p = 0;
27462777
if (lstat(buf, &st) == 0 && S_ISLNK(st.st_mode)) {
2747-
is_symlink = 1;
27482778
p = strrdirsep(buf);
27492779
if (!p) p = skipprefix(buf);
27502780
if (p) {
@@ -2757,7 +2787,8 @@ file_expand_path(fname, dname, result)
27572787
}
27582788
if (p) *p = sep;
27592789
else p = buf;
2760-
if (is_symlink && b == w32buf) {
2790+
if (b == w32buf) {
2791+
strlcat(w32buf, p, sizeof(w32buf));
27612792
len = strlen(p);
27622793
if (len > 4 && strcasecmp(p + len - 4, ".lnk") != 0) {
27632794
lnk_added = 1;
@@ -2785,6 +2816,8 @@ file_expand_path(fname, dname, result)
27852816
#endif
27862817

27872818
if (tainted) OBJ_TAINT(result);
2819+
RSTRING(result)->len = buflen;
2820+
RSTRING(result)->ptr[buflen] = '\0';
27882821
return result;
27892822
}
27902823

@@ -2847,7 +2880,12 @@ rmext(p, l1, e)
28472880
}
28482881
if (l1 < l2) return l1;
28492882

2850-
if (strncmp(p+l1-l2, e, l2) == 0) {
2883+
#if CASEFOLD_FILESYSTEM
2884+
#define fncomp strncasecmp
2885+
#else
2886+
#define fncomp strncmp
2887+
#endif
2888+
if (fncomp(p+l1-l2, e, l2) == 0) {
28512889
return l1-l2;
28522890
}
28532891
return 0;
@@ -2926,7 +2964,7 @@ rb_file_s_basename(argc, argv)
29262964
if (NIL_P(fext) || !(f = rmext(p, n, StringValueCStr(fext)))) {
29272965
f = n;
29282966
}
2929-
if (f == RSTRING(fname)->len) return fname;
2967+
if (f == RSTRING(fname)->len) return fname;
29302968
}
29312969
basename = rb_str_new(p, f);
29322970
OBJ_INFECT(basename, fname);
@@ -3009,7 +3047,7 @@ rb_file_s_extname(klass, fname)
30093047
if (!p)
30103048
p = name;
30113049
else
3012-
name = ++p;
3050+
p++;
30133051

30143052
e = 0;
30153053
while (*p) {
@@ -3039,7 +3077,7 @@ rb_file_s_extname(klass, fname)
30393077
break;
30403078
p = CharNext(p);
30413079
}
3042-
if (!e || e == name || e+1 == p) /* no dot, or the only dot is first or end? */
3080+
if (!e || e+1 == p) /* no dot, or the only dot is first or end? */
30433081
return rb_str_new(0, 0);
30443082
extname = rb_str_new(e, p - e); /* keep the dot, too! */
30453083
OBJ_INFECT(extname, fname);

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2008-06-15"
33
#define RUBY_VERSION_CODE 185
44
#define RUBY_RELEASE_CODE 20080615
5-
#define RUBY_PATCHLEVEL 208
5+
#define RUBY_PATCHLEVEL 209
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy