1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* file.c (rb_find_file_ext, rb_find_file): not to split load path with

path separator.  [ruby-Bugs-21356]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-07-28 09:15:48 +00:00
parent 66660a893a
commit 31aa0986b8
2 changed files with 32 additions and 55 deletions

View file

@ -1,3 +1,8 @@
Mon Jul 28 18:15:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org> Mon Jul 28 18:14:03 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (overlapped_socket_io, fcntl, rb_w32_close): must not * win32/win32.c (overlapped_socket_io, fcntl, rb_w32_close): must not

82
file.c
View file

@ -4447,34 +4447,16 @@ file_load_ok(const char *path)
return eaccess(path, R_OK) == 0; 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); VALUE rb_get_load_path(void);
int int
rb_find_file_ext(VALUE *filep, const char *const *ext) rb_find_file_ext(VALUE *filep, const char *const *ext)
{ {
const char *path, *found;
const char *f = RSTRING_PTR(*filep); const char *f = RSTRING_PTR(*filep);
VALUE fname, load_path; VALUE fname, load_path, tmp;
long i, j; long i, j, fnlen;
if (!ext[0]) return 0;
if (f[0] == '~') { if (f[0] == '~') {
fname = rb_file_expand_path(*filep, Qnil); fname = rb_file_expand_path(*filep, Qnil);
@ -4502,24 +4484,26 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
load_path = rb_get_load_path(); load_path = rb_get_load_path();
if (!load_path) return 0; 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++) { for (j=0; ext[j]; j++) {
fname = rb_str_dup(*filep);
rb_str_cat2(fname, ext[j]); rb_str_cat2(fname, ext[j]);
OBJ_FREEZE(fname);
for (i = 0; i < RARRAY_LEN(load_path); i++) { for (i = 0; i < RARRAY_LEN(load_path); i++) {
VALUE str = RARRAY_PTR(load_path)[i]; VALUE str = RARRAY_PTR(load_path)[i];
char fbuf[MAXPATHLEN];
FilePathValue(str); FilePathValue(str);
if (RSTRING_LEN(str) == 0) continue; if (RSTRING_LEN(str) == 0) continue;
intern_path(str); file_expand_path(fname, str, tmp);
path = RSTRING_PTR(str); if (file_load_ok(RSTRING_PTR(tmp))) {
found = dln_find_file_r(StringValueCStr(fname), path, fbuf, sizeof(fbuf)); RBASIC(tmp)->klass = RBASIC(*filep)->klass;
if (found && file_load_ok(found)) { OBJ_FREEZE(tmp);
*filep = rb_str_new2(found); *filep = tmp;
return j+1; return j+1;
} }
} }
rb_str_set_len(fname, fnlen);
} }
RB_GC_GUARD(load_path); RB_GC_GUARD(load_path);
return 0; return 0;
@ -4530,8 +4514,6 @@ rb_find_file(VALUE path)
{ {
VALUE tmp, load_path; VALUE tmp, load_path;
const char *f = StringValueCStr(path); const char *f = StringValueCStr(path);
const char *lpath;
char fbuf[MAXPATHLEN];
if (f[0] == '~') { if (f[0] == '~') {
path = rb_file_expand_path(path, Qnil); path = rb_file_expand_path(path, Qnil);
@ -4548,6 +4530,7 @@ rb_find_file(VALUE path)
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
} }
if (file_load_ok(f)) return path; if (file_load_ok(f)) return path;
return 0;
} }
#endif #endif
@ -4556,6 +4539,7 @@ rb_find_file(VALUE path)
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
} }
if (file_load_ok(f)) return path; if (file_load_ok(f)) return path;
return 0;
} }
if (rb_safe_level() >= 4) { if (rb_safe_level() >= 4) {
@ -4566,42 +4550,30 @@ rb_find_file(VALUE path)
if (load_path) { if (load_path) {
long i; long i;
tmp = rb_ary_new(); tmp = rb_str_tmp_new(MAXPATHLEN + 2);
for (i = 0; i < RARRAY_LEN(load_path); i++) { for (i = 0; i < RARRAY_LEN(load_path); i++) {
VALUE str = RARRAY_PTR(load_path)[i]; VALUE str = RARRAY_PTR(load_path)[i];
FilePathValue(str); FilePathValue(str);
if (RSTRING_LEN(str) > 0) { if (RSTRING_LEN(str) > 0) {
intern_path(str); file_expand_path(path, str, tmp);
rb_ary_push(tmp, str); f = RSTRING_PTR(tmp);
if (file_load_ok(f)) goto found;
} }
} }
tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP)); return 0;
if (RSTRING_LEN(tmp) == 0) { found:
lpath = 0; RBASIC(tmp)->klass = RBASIC(path)->klass;
} OBJ_FREEZE(tmp);
else {
lpath = RSTRING_PTR(tmp);
}
} }
else { else {
lpath = 0;
}
if (!lpath) {
return 0; /* no path, no load */ 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)) { if (rb_safe_level() >= 1 && !fpath_check(f)) {
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
} }
if (file_load_ok(f)) {
tmp = rb_str_new2(f); return tmp;
OBJ_FREEZE(tmp);
return tmp;
}
return 0;
} }
static void static void