summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ruby.c9
-rw-r--r--test/ruby/test_rubyoptions.rb5
3 files changed, 18 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d16f5b4dcc..514fb630cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/ruby.c b/ruby.c
index c18787458b..22fb5ffe5d 100644
--- a/ruby.c
+++ b/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);
}
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 339999a17e..93dcf43380 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -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