From 48ed66868cad5492ab895cc9aeb1f3a1d272ac46 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 6 May 2016 22:58:03 +0000 Subject: 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ process.c | 16 ++++++++++++++-- test/ruby/test_process.rb | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ddf96b5c8..6f0654724b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat May 7 07:58:02 2016 Nobuyoshi Nakada + + * 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 * enum.c (enum_find): [DOC] add more examples to the documentation diff --git a/process.c b/process.c index 6f3fc235f2..75f51c8a76 100644 --- a/process.c +++ b/process.c @@ -1985,13 +1985,25 @@ rb_check_argv(int argc, VALUE *argv) return prog; } +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 **argv_p, int accept_shell, VALUE *env_ret, V } 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)--; diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 8d6274adf3..28617b60b4 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2256,4 +2256,22 @@ EOS 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 -- cgit v1.2.3