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

ruby-changes:42860

From: nobu <ko1@a...>
Date: Sat, 7 May 2016 07:01:36 +0900 (JST)
Subject: [ruby-changes:42860] nobu:r54934 (trunk): process.c: argument types over conversion

nobu	2016-05-07 07:58:03 +0900 (Sat, 07 May 2016)

  New Revision: 54934

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54934

  Log:
    process.c: argument types over conversion
    
    * process.c (rb_exec_getargs): honor the expected argument types
      over the conversion method.  the basic language functionality
      should be robust.  [ruby-core:75388] [Bug #12355]

  Modified files:
    trunk/ChangeLog
    trunk/process.c
    trunk/test/ruby/test_process.rb
Index: process.c
===================================================================
--- process.c	(revision 54933)
+++ process.c	(revision 54934)
@@ -1986,12 +1986,24 @@ rb_check_argv(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L1986
 }
 
 static VALUE
+check_hash(VALUE obj)
+{
+    if (RB_SPECIAL_CONST_P(obj)) return Qnil;
+    switch (RB_BUILTIN_TYPE(obj)) {
+      case T_STRING:
+      case T_ARRAY:
+	return Qnil;
+    }
+    return rb_check_hash_type(obj);
+}
+
+static VALUE
 rb_exec_getargs(int *argc_p, VALUE **argv_p, int accept_shell, VALUE *env_ret, VALUE *opthash_ret)
 {
     VALUE hash, prog;
 
     if (0 < *argc_p) {
-        hash = rb_check_hash_type((*argv_p)[*argc_p-1]);
+        hash = check_hash((*argv_p)[*argc_p-1]);
         if (!NIL_P(hash)) {
             *opthash_ret = hash;
             (*argc_p)--;
@@ -1999,7 +2011,7 @@ rb_exec_getargs(int *argc_p, VALUE **arg https://github.com/ruby/ruby/blob/trunk/process.c#L2011
     }
 
     if (0 < *argc_p) {
-        hash = rb_check_hash_type((*argv_p)[0]);
+        hash = check_hash((*argv_p)[0]);
         if (!NIL_P(hash)) {
             *env_ret = hash;
             (*argc_p)--;
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 54933)
+++ test/ruby/test_process.rb	(revision 54934)
@@ -2256,4 +2256,22 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L2256
       system(bin, "--disable=gems", "-w", "-e", "puts ARGV", *args)
     end;
   end
+
+  def test_to_hash_on_arguments
+    all_assertions do |a|
+      %w[Array String].each do |type|
+        a.for(type) do
+          assert_separately(['-', EnvUtil.rubybin], <<~"END;")
+          class #{type}
+            def to_hash
+              raise "[Bug-12355]: #{type}#to_hash is called"
+            end
+          end
+          ex = ARGV[0]
+          assert_equal(true, system([ex, ex], "-e", ""))
+          END;
+        end
+      end
+    end
+  end
 end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54933)
+++ ChangeLog	(revision 54934)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May  7 07:58:02 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* process.c (rb_exec_getargs): honor the expected argument types
+	  over the conversion method.  the basic language functionality
+	  should be robust.  [ruby-core:75388] [Bug #12355]
+
 Fri May  6 08:16:26 2016  David Silva  <david.silva@d...>
 
 	* enum.c (enum_find): [DOC] add more examples to the documentation

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

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