summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-14 08:12:05 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-14 08:12:05 +0000
commita164f6bab9690993ff2a3adc49e6906e8c143577 (patch)
tree3032b88228bff1bcdfb2bd8a0b8e9e2abe643736
parent408504ef2265fdeca25b0c8d782a42b65f83d5b6 (diff)
merges r28795 and r28796 from trunk into ruby_1_9_2.
-- * file.c (file_expand_path): should check if could find user. [ruby-core:31538] -- * file.c (file_expand_path): home directory must be absolute. [ruby-core:31537] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--file.c22
-rw-r--r--test/ruby/test_file_exhaustive.rb17
3 files changed, 40 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 72e9c31d1a..b6f1962fbe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Jul 30 08:51:51 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (file_expand_path): home directory must be absolute.
+ [ruby-core:31537]
+
+Fri Jul 30 08:33:20 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (file_expand_path): should check if could find user.
+ [ruby-core:31538]
+
Sat Aug 7 13:33:25 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_eval.c (vm_call0): fix for VM_METHOD_TYPE_NOTIMPLEMENTED.
diff --git a/file.c b/file.c
index 7c5367ff3a..0f1e24ba2e 100644
--- a/file.c
+++ b/file.c
@@ -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,13 +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");
+ }
}
- rb_home_dir(buf, result);
BUFINIT();
p = pend;
}
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 6d71579f09..4615bceb05 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -396,11 +396,20 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_match(/\Ac:\//i, File.expand_path('c:'), '[ruby-core:31591]')
end
assert_kind_of(String, File.expand_path("~"))
- unless /mingw|mswin/ =~ RUBY_PLATFORM
- assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") }
- assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha", "/") }
+ assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") }
+ assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha", "/") }
+ begin
+ bug3630 = '[ruby-core:31537]'
+ home = ENV["HOME"]
+ ENV["HOME"] = nil
+ assert_raise(ArgumentError) { File.expand_path("~") }
+ ENV["HOME"] = "~"
+ assert_raise(ArgumentError, bug3630) { File.expand_path("~") }
+ ENV["HOME"] = "."
+ assert_raise(ArgumentError, bug3630) { File.expand_path("~") }
+ ensure
+ ENV["HOME"] = home
end
-
assert_incompatible_encoding {|d| File.expand_path(d)}
end