1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-04-30 10:51:13 +00:00
parent 0e42b43497
commit 7132479960
3 changed files with 16 additions and 11 deletions

View file

@ -1,3 +1,9 @@
Thu Apr 30 19:51:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <hsbt@ruby-lang.org> Thu Apr 30 17:02:33 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* rational.c: Added documentation for rational literal. * rational.c: Added documentation for rational literal.

View file

@ -4179,8 +4179,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_SEQ(ret, args); ADD_SEQ(ret, args);
} }
ADD_INSN1(ret, line, dupn, FIXNUM_INC(argc, 1 + boff)); ADD_INSN1(ret, line, dupn, FIXNUM_INC(argc, 1 + boff));
flag |= asgnflag;
ADD_SEND_WITH_FLAG(ret, line, idAREF, argc, INT2FIX(flag)); ADD_SEND_WITH_FLAG(ret, line, idAREF, argc, INT2FIX(flag));
flag |= asgnflag;
if (id == 0 || id == 1) { if (id == 0 || id == 1) {
/* 0: or, 1: and /* 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); asgnflag = COMPILE_RECV(ret, "NODE_OP_ASGN2#recv", node);
ADD_INSN(ret, line, dup); 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 */ if (atype == 0 || atype == 1) { /* 0: OR or 1: AND */
ADD_INSN(ret, line, dup); 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); DECL_ANCHOR(args);
unsigned int flag = 0; unsigned int flag = 0;
VALUE argc; VALUE argc;
int asgnflag;
/* optimization shortcut /* optimization shortcut
* obj["literal"] = value -> opt_aset_with(obj, "literal", value) * 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); INIT_ANCHOR(args);
argc = setup_args(iseq, args, node->nd_args, &flag, NULL); 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("argc", argc);
debugp_param("nd_mid", ID2SYM(node->nd_mid)); 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)); ADD_INSN1(ret, line, topn, INT2FIX(1));
if (flag & VM_CALL_ARGS_SPLAT) { if (flag & VM_CALL_ARGS_SPLAT) {
ADD_INSN1(ret, line, putobject, INT2FIX(-1)); 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_INSN1(ret, line, setn, FIXNUM_INC(argc, 3));
ADD_INSN (ret, line, pop); 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) { else if (flag & VM_CALL_ARGS_SPLAT) {
ADD_INSN(ret, line, dup); ADD_INSN(ret, line, dup);
ADD_INSN1(ret, line, putobject, INT2FIX(-1)); 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_INSN1(ret, line, setn, FIXNUM_INC(argc, 2));
ADD_INSN (ret, line, pop); ADD_INSN (ret, line, pop);
} }

View file

@ -102,7 +102,7 @@ class TestAssignment < Test::Unit::TestCase
end end
def test_assign_private_self def test_assign_private_self
bug9907 = '[ruby-core:62949] [Bug #9907]' bug11096 = '[ruby-core:68984] [Bug #11096]'
o = Object.new o = Object.new
class << o class << o
@ -127,17 +127,17 @@ class TestAssignment < Test::Unit::TestCase
assert_equal(1, o.instance_eval {self[0] = 1}) 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_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_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_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}) assert_equal(1, o.instance_eval {self[0] &&= 1})
} }
end end