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
This commit is contained in:
usa 2016-06-10 08:39:51 +00:00
parent 5287eb7453
commit a05bfd4941
4 changed files with 39 additions and 3 deletions

View file

@ -1,3 +1,9 @@
Fri Jun 10 17:34:09 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <nobu@ruby-lang.org> Fri Jun 10 16:30:16 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (new_if_gen): set newline flag to NODE_IF to trace all * parse.y (new_if_gen): set newline flag to NODE_IF to trace all

View file

@ -2011,13 +2011,25 @@ rb_check_argv(int argc, VALUE *argv)
return prog; 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 static VALUE
rb_exec_getargs(int *argc_p, VALUE **argv_p, int accept_shell, VALUE *env_ret, VALUE *opthash_ret) rb_exec_getargs(int *argc_p, VALUE **argv_p, int accept_shell, VALUE *env_ret, VALUE *opthash_ret)
{ {
VALUE hash, prog; VALUE hash, prog;
if (0 < *argc_p) { 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)) { if (!NIL_P(hash)) {
*opthash_ret = hash; *opthash_ret = hash;
(*argc_p)--; (*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) { if (0 < *argc_p) {
hash = rb_check_hash_type((*argv_p)[0]); hash = check_hash((*argv_p)[0]);
if (!NIL_P(hash)) { if (!NIL_P(hash)) {
*env_ret = hash; *env_ret = hash;
(*argc_p)--; (*argc_p)--;

View file

@ -2041,4 +2041,22 @@ EOS
status = th.value status = th.value
assert status.success?, status.inspect assert status.success?, status.inspect
end if defined?(fork) 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 end

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.6" #define RUBY_VERSION "2.2.6"
#define RUBY_RELEASE_DATE "2016-06-10" #define RUBY_RELEASE_DATE "2016-06-10"
#define RUBY_PATCHLEVEL 335 #define RUBY_PATCHLEVEL 336
#define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 6 #define RUBY_RELEASE_MONTH 6