* file.c (file_expand_path): should not upward beyond share name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db0539c447
commit
42de8af413
@ -1,3 +1,7 @@
|
|||||||
|
Thu Feb 20 18:11:01 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* file.c (file_expand_path): should not upward beyond share name.
|
||||||
|
|
||||||
Thu Feb 20 15:45:33 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
Thu Feb 20 15:45:33 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* missing.h (strtoul): fix prototype of strtoul.
|
* missing.h (strtoul): fix prototype of strtoul.
|
||||||
|
50
file.c
50
file.c
@ -1434,6 +1434,26 @@ nextdirsep(s)
|
|||||||
return (char *)s;
|
return (char *)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline char *
|
||||||
|
skipprefix(path)
|
||||||
|
const char *path;
|
||||||
|
{
|
||||||
|
#ifdef DOSISH_UNC
|
||||||
|
if (isdirsep(path[0]) && isdirsep(path[1])) {
|
||||||
|
if (*(path = nextdirsep(path + 2)))
|
||||||
|
path = nextdirsep(path + 1);
|
||||||
|
return (char *)path;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef DOSISH_DRIVE_LETTER
|
||||||
|
if (has_drive_letter(path))
|
||||||
|
return (char *)(path + 2);
|
||||||
|
#endif
|
||||||
|
while (isdirsep(*path)) path++;
|
||||||
|
return (char *)path;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
strrdirsep(path)
|
strrdirsep(path)
|
||||||
const char *path;
|
const char *path;
|
||||||
@ -1494,7 +1514,7 @@ static VALUE
|
|||||||
file_expand_path(fname, dname, result)
|
file_expand_path(fname, dname, result)
|
||||||
VALUE fname, dname, result;
|
VALUE fname, dname, result;
|
||||||
{
|
{
|
||||||
char *s, *buf, *b, *p, *pend;
|
char *s, *buf, *b, *p, *pend, *root;
|
||||||
long buflen;
|
long buflen;
|
||||||
int tainted;
|
int tainted;
|
||||||
|
|
||||||
@ -1594,14 +1614,8 @@ file_expand_path(fname, dname, result)
|
|||||||
#ifdef DOSISH
|
#ifdef DOSISH
|
||||||
if (isdirsep(*s)) {
|
if (isdirsep(*s)) {
|
||||||
/* specified full path, but not drive letter nor UNC */
|
/* specified full path, but not drive letter nor UNC */
|
||||||
if (has_drive_letter(buf)) {
|
/* we need to get the drive letter or UNC share name */
|
||||||
/* we need to get the drive letter */
|
p = skipprefix(buf);
|
||||||
p = &buf[2];
|
|
||||||
}
|
|
||||||
else if (isdirsep(buf[0]) && isdirsep(buf[1])) {
|
|
||||||
/* or UNC share name */
|
|
||||||
if (*(p = nextdirsep(buf + 2))) p = nextdirsep(p + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@ -1619,6 +1633,9 @@ file_expand_path(fname, dname, result)
|
|||||||
else
|
else
|
||||||
*p = '/';
|
*p = '/';
|
||||||
|
|
||||||
|
p[1] = 0;
|
||||||
|
root = skipprefix(buf);
|
||||||
|
|
||||||
b = s;
|
b = s;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
@ -1632,7 +1649,7 @@ file_expand_path(fname, dname, result)
|
|||||||
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
|
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
|
||||||
/* We must go back to the parent */
|
/* We must go back to the parent */
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (!(b = strrdirsep(buf))) {
|
if (!(b = strrdirsep(root))) {
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1684,6 +1701,13 @@ file_expand_path(fname, dname, result)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_file_expand_path(fname, dname)
|
||||||
|
VALUE fname, dname;
|
||||||
|
{
|
||||||
|
return file_expand_path(fname, dname, rb_str_new(0, MAXPATHLEN + 2));
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_file_s_expand_path(argc, argv)
|
rb_file_s_expand_path(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
@ -1692,7 +1716,7 @@ rb_file_s_expand_path(argc, argv)
|
|||||||
VALUE fname, dname;
|
VALUE fname, dname;
|
||||||
rb_scan_args(argc, argv, "11", &fname, &dname);
|
rb_scan_args(argc, argv, "11", &fname, &dname);
|
||||||
|
|
||||||
return file_expand_path(fname, dname, rb_str_new(0, MAXPATHLEN + 2));
|
return rb_file_expand_path(fname, dname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2653,7 +2677,7 @@ rb_find_file_ext(filep, ext)
|
|||||||
long i, j;
|
long i, j;
|
||||||
|
|
||||||
if (f[0] == '~') {
|
if (f[0] == '~') {
|
||||||
fname = rb_file_s_expand_path(1, filep);
|
fname = rb_file_expand_path(*filep, Qnil);
|
||||||
if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) {
|
if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) {
|
||||||
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
||||||
}
|
}
|
||||||
@ -2704,7 +2728,7 @@ rb_find_file(path)
|
|||||||
char *lpath;
|
char *lpath;
|
||||||
|
|
||||||
if (f[0] == '~') {
|
if (f[0] == '~') {
|
||||||
path = rb_file_s_expand_path(1, &path);
|
path = rb_file_expand_path(path, Qnil);
|
||||||
if (rb_safe_level() >= 2 && OBJ_TAINTED(path)) {
|
if (rb_safe_level() >= 2 && OBJ_TAINTED(path)) {
|
||||||
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user