summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-17 16:27:13 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-17 16:27:13 +0000
commitd60a7d2e82296450585d84d900c4b334fac21e5f (patch)
tree25e5bced8d82d25411d42c6dde9565aa413213f0
parent34783456e8105c65377a4473b466ffeaa581d87e (diff)
merge revision(s) 62952: [Backport #14638]
win32/file.c: relative path with drive letter * win32/file.c (IS_ABSOLUTE_PATH_P): home directory should not be a relative path regardless a drive letter. PathIsRelativeW returns FALSE on such path. [ruby-core:86356] [Bug #14638] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_file_exhaustive.rb2
-rw-r--r--version.h2
-rw-r--r--win32/file.c15
3 files changed, 15 insertions, 4 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 9e8000f41a..817c3580d1 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -891,6 +891,8 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_raise(ArgumentError) { File.expand_path(".", UnknownUserHome) }
assert_nothing_raised(ArgumentError) { File.expand_path("#{DRIVE}/", UnknownUserHome) }
+ ENV["HOME"] = "#{DRIVE}UserHome"
+ assert_raise(ArgumentError) { File.expand_path("~") }
ensure
ENV["HOME"] = home
end
diff --git a/version.h b/version.h
index b4ac1f5bad..39916a10aa 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.5.2"
#define RUBY_RELEASE_DATE "2018-08-18"
-#define RUBY_PATCHLEVEL 71
+#define RUBY_PATCHLEVEL 72
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 8
diff --git a/win32/file.c b/win32/file.c
index 6f157d4d38..fe3f7c02d3 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -22,6 +22,15 @@ static struct code_page_table {
#define IS_DIR_SEPARATOR_P(c) (c == L'\\' || c == L'/')
#define IS_DIR_UNC_P(c) (IS_DIR_SEPARATOR_P(c[0]) && IS_DIR_SEPARATOR_P(c[1]))
+static int
+IS_ABSOLUTE_PATH_P(const WCHAR *path, size_t len)
+{
+ if (len < 2) return FALSE;
+ if (ISALPHA(path[0]))
+ return len > 2 && path[1] == L':' && IS_DIR_SEPARATOR_P(path[2]);
+ else
+ return IS_DIR_UNC_P(path);
+}
/* MultiByteToWideChar() doesn't work with code page 51932 */
#define INVALID_CODE_PAGE 51932
@@ -315,7 +324,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
}
whome_len = wcslen(whome);
- if (PathIsRelativeW(whome) && !(whome_len >= 2 && IS_DIR_UNC_P(whome))) {
+ if (!IS_ABSOLUTE_PATH_P(whome, whome_len)) {
free(wpath);
xfree(whome);
rb_raise(rb_eArgError, "non-absolute home");
@@ -397,7 +406,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
}
whome_len = wcslen(whome);
- if (PathIsRelativeW(whome) && !(whome_len >= 2 && IS_DIR_UNC_P(whome))) {
+ if (!IS_ABSOLUTE_PATH_P(whome, whome_len)) {
free(wpath);
free(wdir);
xfree(whome);
@@ -523,7 +532,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
buffer_pos[0] = L'\0';
/* tainted if path is relative */
- if (!tainted && PathIsRelativeW(buffer) && !(buffer_len >= 2 && IS_DIR_UNC_P(buffer)))
+ if (!tainted && !IS_ABSOLUTE_PATH_P(buffer, buffer_len))
tainted = 1;
/* FIXME: Make this more robust */