From 7132479960cff87e0d7e3fb5cb3919b791edfecc Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 30 Apr 2015 10:51:13 +0000 Subject: [PATCH] compile.c: disallow private readers * compile.c (iseq_compile_each): revert r46873 and r46875, not to allow to execute private readers by pretending op assign. [ruby-core:68984] [Bug #11096] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ compile.c | 11 +++++------ test/ruby/test_assignment.rb | 10 +++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index e05954f3f0..fd55d5d22b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Apr 30 19:51:11 2015 Nobuyoshi Nakada + + * compile.c (iseq_compile_each): revert r46873 and r46875, not to + allow to execute private readers by pretending op assign. + [ruby-core:68984] [Bug #11096] + Thu Apr 30 17:02:33 2015 SHIBATA Hiroshi * rational.c: Added documentation for rational literal. diff --git a/compile.c b/compile.c index 9427ade1c9..e5cf964530 100644 --- a/compile.c +++ b/compile.c @@ -4179,8 +4179,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_SEQ(ret, args); } ADD_INSN1(ret, line, dupn, FIXNUM_INC(argc, 1 + boff)); - flag |= asgnflag; ADD_SEND_WITH_FLAG(ret, line, idAREF, argc, INT2FIX(flag)); + flag |= asgnflag; if (id == 0 || id == 1) { /* 0: or, 1: and @@ -4319,7 +4319,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) asgnflag = COMPILE_RECV(ret, "NODE_OP_ASGN2#recv", node); ADD_INSN(ret, line, dup); - ADD_SEND_WITH_FLAG(ret, line, node->nd_next->nd_vid, INT2FIX(0), INT2FIX(asgnflag)); + ADD_SEND(ret, line, node->nd_next->nd_vid, INT2FIX(0)); if (atype == 0 || atype == 1) { /* 0: OR or 1: AND */ ADD_INSN(ret, line, dup); @@ -5479,7 +5479,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) DECL_ANCHOR(args); unsigned int flag = 0; VALUE argc; - int asgnflag; /* optimization shortcut * obj["literal"] = value -> opt_aset_with(obj, "literal", value) @@ -5509,7 +5508,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) INIT_ANCHOR(args); argc = setup_args(iseq, args, node->nd_args, &flag, NULL); - flag |= (asgnflag = COMPILE_RECV(recv, "recv", node)); + flag |= COMPILE_RECV(recv, "recv", node); debugp_param("argc", argc); debugp_param("nd_mid", ID2SYM(node->nd_mid)); @@ -5523,7 +5522,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN1(ret, line, topn, INT2FIX(1)); if (flag & VM_CALL_ARGS_SPLAT) { ADD_INSN1(ret, line, putobject, INT2FIX(-1)); - ADD_SEND_WITH_FLAG(ret, line, idAREF, INT2FIX(1), INT2FIX(asgnflag)); + ADD_SEND(ret, line, idAREF, INT2FIX(1)); } ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 3)); ADD_INSN (ret, line, pop); @@ -5531,7 +5530,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) else if (flag & VM_CALL_ARGS_SPLAT) { ADD_INSN(ret, line, dup); ADD_INSN1(ret, line, putobject, INT2FIX(-1)); - ADD_SEND_WITH_FLAG(ret, line, idAREF, INT2FIX(1), INT2FIX(asgnflag)); + ADD_SEND(ret, line, idAREF, INT2FIX(1)); ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 2)); ADD_INSN (ret, line, pop); } diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index 9c0fd48725..315f7baef6 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -102,7 +102,7 @@ class TestAssignment < Test::Unit::TestCase end def test_assign_private_self - bug9907 = '[ruby-core:62949] [Bug #9907]' + bug11096 = '[ruby-core:68984] [Bug #11096]' o = Object.new class << o @@ -127,17 +127,17 @@ class TestAssignment < Test::Unit::TestCase assert_equal(1, o.instance_eval {self[0] = 1}) } - assert_nothing_raised(NoMethodError, bug9907) { + assert_raise(NoMethodError, bug11096) { assert_equal(43, o.instance_eval {self.foo += 1}) } - assert_nothing_raised(NoMethodError, bug9907) { + assert_raise(NoMethodError, bug11096) { assert_equal(1, o.instance_eval {self.foo &&= 1}) } - assert_nothing_raised(NoMethodError, bug9907) { + assert_raise(NoMethodError, bug11096) { assert_equal(43, o.instance_eval {self[0] += 1}) } - assert_nothing_raised(NoMethodError, bug9907) { + assert_raise(NoMethodError, bug11096) { assert_equal(1, o.instance_eval {self[0] &&= 1}) } end