ruby-changes:36470
From: nobu <ko1@a...>
Date: Mon, 24 Nov 2014 12:45:13 +0900 (JST)
Subject: [ruby-changes:36470] nobu:r48552 (trunk): process.c: get rid of inadvertent ID pindown
nobu 2014-11-24 12:44:45 +0900 (Mon, 24 Nov 2014) New Revision: 48552 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48552 Log: process.c: get rid of inadvertent ID pindown * process.c (check_exec_redirect_fd, check_exec_redirect), (rb_execarg_addopt): get rid of inadvertent ID pindown. Modified files: trunk/ChangeLog trunk/process.c trunk/test/-ext-/symbol/test_inadvertent_creation.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48551) +++ ChangeLog (revision 48552) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Nov 24 12:44:35 2014 Nobuyoshi Nakada <nobu@r...> + + * process.c (check_exec_redirect_fd, check_exec_redirect), + (rb_execarg_addopt): get rid of inadvertent ID pindown. + Mon Nov 24 02:03:40 2014 Nobuyoshi Nakada <nobu@r...> * string.c (rb_str_setter): preserve encoding of global variable Index: process.c =================================================================== --- process.c (revision 48551) +++ process.c (revision 48552) @@ -1489,7 +1489,7 @@ check_exec_redirect_fd(VALUE v, int iske https://github.com/ruby/ruby/blob/trunk/process.c#L1489 fd = FIX2INT(v); } else if (SYMBOL_P(v)) { - ID id = SYM2ID(v); + ID id = rb_check_id(&v); if (id == id_in) fd = 0; else if (id == id_out) @@ -1553,7 +1553,7 @@ check_exec_redirect(VALUE key, VALUE val https://github.com/ruby/ruby/blob/trunk/process.c#L1553 switch (TYPE(val)) { case T_SYMBOL: - id = SYM2ID(val); + if (!(id = rb_check_id(&val))) goto wrong_symbol; if (id == id_close) { param = Qnil; eargp->fd_close = check_exec_redirect1(eargp->fd_close, key, param); @@ -1571,8 +1571,9 @@ check_exec_redirect(VALUE key, VALUE val https://github.com/ruby/ruby/blob/trunk/process.c#L1571 eargp->fd_dup2 = check_exec_redirect1(eargp->fd_dup2, key, param); } else { - rb_raise(rb_eArgError, "wrong exec redirect symbol: %s", - rb_id2name(id)); + wrong_symbol: + rb_raise(rb_eArgError, "wrong exec redirect symbol: %"PRIsVALUE, + val); } break; @@ -1588,7 +1589,7 @@ check_exec_redirect(VALUE key, VALUE val https://github.com/ruby/ruby/blob/trunk/process.c#L1589 case T_ARRAY: path = rb_ary_entry(val, 0); if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) && - SYM2ID(path) == id_child) { + path == ID2SYM(id_child)) { param = check_exec_redirect_fd(rb_ary_entry(val, 1), 0); eargp->fd_dup2_child = check_exec_redirect1(eargp->fd_dup2_child, key, param); } @@ -1663,7 +1664,7 @@ rb_execarg_addopt(VALUE execarg_obj, VAL https://github.com/ruby/ruby/blob/trunk/process.c#L1664 switch (TYPE(key)) { case T_SYMBOL: - id = SYM2ID(key); + if (!(id = rb_check_id(&key))) return ST_STOP; #ifdef HAVE_SETPGID if (id == id_pgroup) { rb_pid_t pgroup; Index: test/-ext-/symbol/test_inadvertent_creation.rb =================================================================== --- test/-ext-/symbol/test_inadvertent_creation.rb (revision 48551) +++ test/-ext-/symbol/test_inadvertent_creation.rb (revision 48552) @@ -320,5 +320,37 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L320 end end; end + + def test_execopt_key + name = noninterned_name.intern + assert_raise(ArgumentError) { + system(".", name => nil) + } + assert_not_pinneddown(name) + end + + def test_execopt_redirect_value + name = noninterned_name.intern + assert_raise(ArgumentError) { + system(".", [] => name) + } + assert_not_pinneddown(name) + end + + def test_execopt_redirect_path + name = noninterned_name.intern + assert_raise(TypeError) { + system(".", [] => [name, 0]) + } + assert_not_pinneddown(name) + end + + def test_execopt_redirect_symbol + name = noninterned_name.intern + assert_raise(ArgumentError) { + system(".", in: name) + } + assert_not_pinneddown(name) + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/