[前][次][番号順一覧][スレッド一覧]

ruby-changes:23081

From: nobu <ko1@a...>
Date: Mon, 26 Mar 2012 11:46:15 +0900 (JST)
Subject: [ruby-changes:23081] nobu:r35131 (trunk): * ruby.c (load_file_internal): bail out if the script is a directory.

nobu	2012-03-26 11:46:04 +0900 (Mon, 26 Mar 2012)

  New Revision: 35131

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35131

  Log:
    * ruby.c (load_file_internal): bail out if the script is a directory.
      [Feature #2408][ruby-core:26925]

  Modified files:
    trunk/ChangeLog
    trunk/ruby.c
    trunk/test/ruby/test_rubyoptions.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35130)
+++ ChangeLog	(revision 35131)
@@ -1,5 +1,8 @@
-Mon Mar 26 11:41:01 2012  Nobuyoshi Nakada  <nobu@r...>
+Mon Mar 26 11:46:01 2012  Nobuyoshi Nakada  <nobu@r...>
 
+	* 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.
 
Index: ruby.c
===================================================================
--- ruby.c	(revision 35130)
+++ ruby.c	(revision 35131)
@@ -1524,9 +1524,18 @@
 	}
 #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);
     }
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 35130)
+++ test/ruby/test_rubyoptions.rb	(revision 35131)
@@ -553,4 +553,9 @@
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]