[前][次][番号順一覧][スレッド一覧]

ruby-changes:38327

From: nobu <ko1@a...>
Date: Thu, 30 Apr 2015 19:51:32 +0900 (JST)
Subject: [ruby-changes:38327] nobu:r50408 (trunk): compile.c: disallow private readers

nobu	2015-04-30 19:51:13 +0900 (Thu, 30 Apr 2015)

  New Revision: 50408

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50408

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_assignment.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50407)
+++ ChangeLog	(revision 50408)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Apr 30 19:51:11 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* rational.c: Added documentation for rational literal.
Index: compile.c
===================================================================
--- compile.c	(revision 50407)
+++ compile.c	(revision 50408)
@@ -4179,8 +4179,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4179
 	    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_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4319
 
 	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_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5479
 	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_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5508
 	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_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5522
 		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_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5530
 	    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);
 	    }
Index: test/ruby/test_assignment.rb
===================================================================
--- test/ruby/test_assignment.rb	(revision 50407)
+++ test/ruby/test_assignment.rb	(revision 50408)
@@ -102,7 +102,7 @@ class TestAssignment < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_assignment.rb#L102
   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::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_assignment.rb#L127
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]