From 764d54788a85b2238cb9f5e93dfaa0385c02f47f Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 26 Mar 2012 02:46:04 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 ++++- ruby.c | 9 +++++++++ test/ruby/test_rubyoptions.rb | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) 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 +Mon Mar 26 11:46:01 2012 Nobuyoshi Nakada + + * 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