summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-22 04:54:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-22 04:54:35 +0000
commitcfa3ebf47c33d930c58ac735db65dd2e3346367a (patch)
tree9dff0d9f89dd0b5cf4dd8354da2eef370436f818 /win32
parent0109f86871d07f65255df6e813a49bc272f5ece8 (diff)
file.c: check arguments lengths
* win32/file.c (rb_file_expand_path_internal): check arguments lengths and should not loose preci quielty. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/file.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/win32/file.c b/win32/file.c
index 0fddaaa..1884f2a 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -350,7 +350,14 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
/* convert char * to wchar_t */
if (!NIL_P(path)) {
- wpath = mbstr_to_wstr(cp, RSTRING_PTR(path), (int)RSTRING_LEN(path), &wpath_len);
+ const long path_len = RSTRING_LEN(path);
+#if SIZEOF_INT < SIZEOF_LONG
+ if ((long)(int)path_len != path_len) {
+ rb_raise(rb_eRangeError, "path (%ld bytes) is too long",
+ path_len);
+ }
+#endif
+ wpath = mbstr_to_wstr(cp, RSTRING_PTR(path), path_len, &wpath_len);
wpath_pos = wpath;
}
@@ -425,7 +432,15 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
/* convert char * to wchar_t */
if (!NIL_P(dir)) {
- wdir = mbstr_to_wstr(cp, RSTRING_PTR(dir), (int)RSTRING_LEN(dir), &wdir_len);
+ const long dir_len = RSTRING_LEN(dir);
+#if SIZEOF_INT < SIZEOF_LONG
+ if ((long)(int)dir_len != dir_len) {
+ if (wpath) xfree(wpath);
+ rb_raise(rb_eRangeError, "base directory (%ld bytes) is too long",
+ dir_len);
+ }
+#endif
+ wdir = mbstr_to_wstr(cp, RSTRING_PTR(dir), dir_len, &wdir_len);
wdir_pos = wdir;
}