ruby-changes:6727
From: nobu <ko1@a...>
Date: Mon, 28 Jul 2008 18:16:07 +0900 (JST)
Subject: [ruby-changes:6727] Ruby:r18242 (trunk, ruby_1_8): * file.c (rb_find_file_ext, rb_find_file): not to split load path with
nobu 2008-07-28 18:15:48 +0900 (Mon, 28 Jul 2008) New Revision: 18242 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18242 Log: * file.c (rb_find_file_ext, rb_find_file): not to split load path with path separator. [ruby-Bugs-21356] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/file.c trunk/ChangeLog trunk/file.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18241) +++ ChangeLog (revision 18242) @@ -1,3 +1,8 @@ +Mon Jul 28 18:15:45 2008 Nobuyoshi Nakada <nobu@r...> + + * file.c (rb_find_file_ext, rb_find_file): not to split load path with + path separator. [ruby-Bugs-21356] + Mon Jul 28 18:14:03 2008 Nobuyoshi Nakada <nobu@r...> * win32/win32.c (overlapped_socket_io, fcntl, rb_w32_close): must not Index: file.c =================================================================== --- file.c (revision 18241) +++ file.c (revision 18242) @@ -4447,35 +4447,17 @@ return eaccess(path, R_OK) == 0; } -#ifdef __CYGWIN__ -static void -intern_cygwin_path(volatile VALUE *path) -{ - char rubylib[MAXPATHLEN]; - VALUE str = *path; - const char *p = RSTRING_PTR(str); - - if (*p == '\\' || has_drive_letter(p)) { - if (cygwin_conv_to_posix_path(p, rubylib) == 0) { - *path = rb_str_new2(rubylib); - } - } -} -#define intern_path(str) intern_cygwin_path(&(str)) -#else -#define intern_path(str) (void)(str) -#endif - VALUE rb_get_load_path(void); int rb_find_file_ext(VALUE *filep, const char *const *ext) { - const char *path, *found; const char *f = RSTRING_PTR(*filep); - VALUE fname, load_path; - long i, j; + VALUE fname, load_path, tmp; + long i, j, fnlen; + if (!ext[0]) return 0; + if (f[0] == '~') { fname = rb_file_expand_path(*filep, Qnil); if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) { @@ -4502,24 +4484,26 @@ load_path = rb_get_load_path(); if (!load_path) return 0; + fname = rb_str_dup(*filep); + RBASIC(fname)->klass = 0; + fnlen = RSTRING_LEN(fname); + tmp = rb_str_tmp_new(MAXPATHLEN + 2); for (j=0; ext[j]; j++) { - fname = rb_str_dup(*filep); rb_str_cat2(fname, ext[j]); - OBJ_FREEZE(fname); for (i = 0; i < RARRAY_LEN(load_path); i++) { VALUE str = RARRAY_PTR(load_path)[i]; - char fbuf[MAXPATHLEN]; FilePathValue(str); if (RSTRING_LEN(str) == 0) continue; - intern_path(str); - path = RSTRING_PTR(str); - found = dln_find_file_r(StringValueCStr(fname), path, fbuf, sizeof(fbuf)); - if (found && file_load_ok(found)) { - *filep = rb_str_new2(found); + file_expand_path(fname, str, tmp); + if (file_load_ok(RSTRING_PTR(tmp))) { + RBASIC(tmp)->klass = RBASIC(*filep)->klass; + OBJ_FREEZE(tmp); + *filep = tmp; return j+1; } } + rb_str_set_len(fname, fnlen); } RB_GC_GUARD(load_path); return 0; @@ -4530,8 +4514,6 @@ { VALUE tmp, load_path; const char *f = StringValueCStr(path); - const char *lpath; - char fbuf[MAXPATHLEN]; if (f[0] == '~') { path = rb_file_expand_path(path, Qnil); @@ -4548,6 +4530,7 @@ rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } if (file_load_ok(f)) return path; + return 0; } #endif @@ -4556,6 +4539,7 @@ rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } if (file_load_ok(f)) return path; + return 0; } if (rb_safe_level() >= 4) { @@ -4566,42 +4550,30 @@ if (load_path) { long i; - tmp = rb_ary_new(); + tmp = rb_str_tmp_new(MAXPATHLEN + 2); for (i = 0; i < RARRAY_LEN(load_path); i++) { VALUE str = RARRAY_PTR(load_path)[i]; FilePathValue(str); if (RSTRING_LEN(str) > 0) { - intern_path(str); - rb_ary_push(tmp, str); + file_expand_path(path, str, tmp); + f = RSTRING_PTR(tmp); + if (file_load_ok(f)) goto found; } } - tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP)); - if (RSTRING_LEN(tmp) == 0) { - lpath = 0; - } - else { - lpath = RSTRING_PTR(tmp); - } + return 0; + found: + RBASIC(tmp)->klass = RBASIC(path)->klass; + OBJ_FREEZE(tmp); } else { - lpath = 0; - } - - if (!lpath) { return 0; /* no path, no load */ } - if (!(f = dln_find_file_r(f, lpath, fbuf, sizeof(fbuf)))) { - return 0; - } + if (rb_safe_level() >= 1 && !fpath_check(f)) { rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } - if (file_load_ok(f)) { - tmp = rb_str_new2(f); - OBJ_FREEZE(tmp); - return tmp; - } - return 0; + + return tmp; } static void Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 18241) +++ ruby_1_8/ChangeLog (revision 18242) @@ -1,3 +1,8 @@ +Mon Jul 28 18:15:45 2008 Nobuyoshi Nakada <nobu@r...> + + * file.c (rb_find_file_ext, rb_find_file): not to split load path with + path separator. [ruby-Bugs-21356] + Fri Jul 25 23:35:18 2008 Nobuyoshi Nakada <nobu@r...> * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value): Index: ruby_1_8/file.c =================================================================== --- ruby_1_8/file.c (revision 18241) +++ ruby_1_8/file.c (revision 18242) @@ -4388,25 +4388,6 @@ return 1; } -#ifdef __CYGWIN__ -static void -intern_cygwin_path(volatile VALUE *path) -{ - char rubylib[MAXPATHLEN]; - VALUE str = *path; - const char *p = RSTRING_PTR(str); - - if (*p == '\\' || has_drive_letter(p)) { - if (cygwin_conv_to_posix_path(p, rubylib) == 0) { - *path = rb_str_new2(rubylib); - } - } -} -#define intern_path(str) intern_cygwin_path(&(str)) -#else -#define intern_path(str) (void)(str) -#endif - extern VALUE rb_load_path; int @@ -4414,10 +4395,9 @@ VALUE *filep; const char * const *ext; { - const char *path, *found; const char *f = RSTRING(*filep)->ptr; - VALUE fname; - long i, j; + VALUE fname, tmp; + long i, j, fnlen; if (f[0] == '~') { fname = rb_file_expand_path(*filep, Qnil); @@ -4443,24 +4423,26 @@ } if (!rb_load_path) return 0; - Check_Type(rb_load_path, T_ARRAY); + + tmp = rb_str_tmp_new(MAXPATHLEN + 2); for (i=0;i<RARRAY(rb_load_path)->len;i++) { VALUE str = RARRAY(rb_load_path)->ptr[i]; SafeStringValue(str); if (RSTRING(str)->len == 0) continue; - intern_path(str); - path = RSTRING(str)->ptr; + file_expand_path(*filep, str, tmp); + fnlen = RSTRING_LEN(tmp); for (j=0; ext[j]; j++) { - fname = rb_str_dup(*filep); - rb_str_cat2(fname, ext[j]); - OBJ_FREEZE(fname); - found = dln_find_file(StringValueCStr(fname), path); - if (found && file_load_ok(found)) { + rb_str_cat2(tmp, ext[j]); + if (file_load_ok(RSTRING_PTR(tmp))) { + fname = rb_str_dup(*filep); + rb_str_cat2(fname, ext[j]); + OBJ_FREEZE(fname); *filep = fname; return j+1; } + rb_str_set_len(tmp, fnlen); } } return 0; @@ -4472,7 +4454,6 @@ { VALUE tmp; const char *f = StringValueCStr(path); - const char *lpath; if (f[0] == '~') { path = rb_file_expand_path(path, Qnil); @@ -4489,6 +4470,7 @@ rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } if (file_load_ok(f)) return path; + return 0; } #endif @@ -4497,6 +4479,7 @@ rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } if (file_load_ok(f)) return path; + return 0; } if (rb_safe_level() >= 4) { @@ -4507,42 +4490,30 @@ long i; Check_Type(rb_load_path, T_ARRAY); - tmp = rb_ary_new(); + tmp = rb_str_tmp_new(MAXPATHLEN + 2); for (i=0;i<RARRAY(rb_load_path)->len;i++) { VALUE str = RARRAY(rb_load_path)->ptr[i]; SafeStringValue(str); if (RSTRING(str)->len > 0) { - intern_path(str); - rb_ary_push(tmp, str); + file_expand_path(path, str, tmp); + f = RSTRING_PTR(tmp); + if (file_load_ok(f)) goto found; } } - tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP)); - if (RSTRING(tmp)->len == 0) { - lpath = 0; - } - else { - lpath = RSTRING(tmp)->ptr; - } + return 0; + found: + RBASIC(tmp)->klass = RBASIC(path)->klass; + OBJ_FREEZE(tmp); } else { - lpath = 0; - } - - if (!lpath) { return 0; /* no path, no load */ } - if (!(f = dln_find_file(f, lpath))) { - return 0; - } + if (rb_safe_level() >= 1 && !fpath_check(f)) { rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } - if (file_load_ok(f)) { - tmp = rb_str_new2(f); - OBJ_FREEZE(tmp); - return tmp; - } - return 0; + + return tmp; } static void -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/