* ruby.c (load_file_internal): bail out if the script is a directory.

[Feature #2408][ruby-core:26925]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-26 02:46:04 +00:00
Родитель 8a57e0bf82
Коммит 764d54788a
3 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -1,4 +1,7 @@
Mon Mar 26 11:41:01 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
Mon Mar 26 11:46:01 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (load_file_internal): bail out if the script is a directory.
[Feature #2408][ruby-core:26925]
* win32/win32.c (rb_w32_open, rb_w32_wopen): check if the file is a
directory when access denied, to set errno to EISDIR.

9
ruby.c
Просмотреть файл

@ -1524,9 +1524,18 @@ load_file_internal(VALUE arg)
}
#endif
if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) {
load_failed:
rb_load_fail(fname_v, strerror(errno));
}
rb_update_max_fd(fd);
{
struct stat st;
if (fstat(fd, &st) != 0) goto load_failed;
if (S_ISDIR(st.st_mode)) {
errno = EISDIR;
goto load_failed;
}
}
f = rb_io_fdopen(fd, mode, fname);
}

Просмотреть файл

@ -553,4 +553,9 @@ class TestRubyOptions < Test::Unit::TestCase
assert_in_out_err(["-C", dir, a], "", [], /LoadError/, bug3851)
end
end
def test_script_is_directory
feature2408 = '[ruby-core:26925]'
assert_in_out_err(%w[.], "", [], /Is a directory -- \./, feature2408)
end
end