aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-06 22:58:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-06 22:58:03 +0000
commit48ed66868cad5492ab895cc9aeb1f3a1d272ac46 (patch)
tree2a447cca4fda4dc219a53e6ecf90575e0156e680
parentcc22facc9cbc262e9ff4bee1155751eebcda067e (diff)
downloadruby-48ed66868cad5492ab895cc9aeb1f3a1d272ac46.tar.gz
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
-rw-r--r--ChangeLog6
-rw-r--r--process.c16
-rw-r--r--test/ruby/test_process.rb18
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 <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 May 6 08:16:26 2016 David Silva <david.silva@digital.cabinet-office.gov.uk>
* 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
@@ -1986,12 +1986,24 @@ rb_check_argv(int argc, VALUE *argv)
}
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