diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-29 23:51:53 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-29 23:51:53 +0000 |
commit | 6d56e80ad1bce411b1d4fe425e2842768a3bcfa6 (patch) | |
tree | 9d8dfb5ec52bb35a013f6a1732b24119e48828e1 /file.c | |
parent | a99de8466396ba4d056c126040dbf19ca5af20ff (diff) | |
download | ruby-6d56e80ad1bce411b1d4fe425e2842768a3bcfa6.tar.gz |
* file.c (file_expand_path): home directory must be absolute.
[ruby-core:31537]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -2851,6 +2851,7 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result) tainted = OBJ_TAINTED(fname); if (s[0] == '~' && abs_mode == 0) { /* execute only if NOT absolute_path() */ + long userlen = 0; tainted = 1; if (isdirsep(s[1]) || s[1] == '\0') { buf = 0; @@ -2859,15 +2860,24 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result) } else { s = nextdirsep(b = s); - BUFCHECK(bdiff + (s-b) >= buflen); - memcpy(p, b, s-b); - rb_str_set_len(result, s-b); + userlen = s - b; + BUFCHECK(bdiff + userlen >= buflen); + memcpy(p, b, userlen); + rb_str_set_len(result, userlen); buf = p + 1; - p += s-b; + p += userlen; } if (NIL_P(rb_home_dir(buf, result))) { rb_raise(rb_eArgError, "can't find user %s", buf); } + if (!rb_is_absolute_path(RSTRING_PTR(result))) { + if (userlen) { + rb_raise(rb_eArgError, "non-absolute home of %.*s", (int)userlen, b); + } + else { + rb_raise(rb_eArgError, "non-absolute home"); + } + } BUFINIT(); p = pend; } |