From a05bfd49410bedb5812f8f4e4c27eb1bcd15211e Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 10 Jun 2016 08:39:51 +0000 Subject: [PATCH] merge revision(s) 54934: [Backport #12355] * 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/branches/ruby_2_2@55362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ process.c | 16 ++++++++++++++-- test/ruby/test_process.rb | 18 ++++++++++++++++++ version.h | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e82b48a78b..10b923ff3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jun 10 17:34:09 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 Jun 10 16:30:16 2016 Nobuyoshi Nakada * parse.y (new_if_gen): set newline flag to NODE_IF to trace all diff --git a/process.c b/process.c index 7eeb104f91..8299fcf5cf 100644 --- a/process.c +++ b/process.c @@ -2011,13 +2011,25 @@ rb_check_argv(int argc, VALUE *argv) return prog; } +static VALUE +check_hash(VALUE obj) +{ + if (SPECIAL_CONST_P(obj)) return Qnil; + switch (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)--; @@ -2025,7 +2037,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 459e0a5050..4dadfb49d1 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2041,4 +2041,22 @@ EOS status = th.value assert status.success?, status.inspect end if defined?(fork) + + 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 diff --git a/version.h b/version.h index e8ddf243cb..642a9805c9 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.6" #define RUBY_RELEASE_DATE "2016-06-10" -#define RUBY_PATCHLEVEL 335 +#define RUBY_PATCHLEVEL 336 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 6