mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* vm_insnhelper.c (vm_call_method): protected singleton methods of
an object should not be able to called from other instances of the class of the object. [ruby-core:26761] * vm_eval.c (rb_method_call_status): ditto. * test/ruby/test_module.rb (test_protected_singleton_method): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									98cf9c43fa
								
							
						
					
					
						commit
						3dc8a69df7
					
				
					 4 changed files with 36 additions and 2 deletions
				
			
		
							
								
								
									
										10
									
								
								ChangeLog
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								ChangeLog
									
										
									
									
									
								
							| 
						 | 
					@ -1,3 +1,13 @@
 | 
				
			||||||
 | 
					Mon Nov 16 15:51:53 2009  Shugo Maeda  <shugo@ruby-lang.org>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* vm_insnhelper.c (vm_call_method): protected singleton methods of
 | 
				
			||||||
 | 
						  an object should not be able to called from other instances of the
 | 
				
			||||||
 | 
						  class of the object.  [ruby-core:26761]
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						* vm_eval.c (rb_method_call_status): ditto.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* test/ruby/test_module.rb (test_protected_singleton_method): ditto.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Mon Nov 16 14:03:53 2009  wanabe  <s.wanabe@gmail.com>
 | 
					Mon Nov 16 14:03:53 2009  wanabe  <s.wanabe@gmail.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	* io.c (read_all): shift read buffer if exception occured.
 | 
						* io.c (read_all): shift read buffer if exception occured.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -854,4 +854,28 @@ class TestModule < Test::Unit::TestCase
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    assert_equal("", stderr)
 | 
					    assert_equal("", stderr)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def test_protected_singleton_method
 | 
				
			||||||
 | 
					    klass = Class.new
 | 
				
			||||||
 | 
					    x = klass.new
 | 
				
			||||||
 | 
					    class << x
 | 
				
			||||||
 | 
					      protected
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def foo
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    assert_raise(NoMethodError) do
 | 
				
			||||||
 | 
					      x.foo
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    klass.send(:define_method, :bar) do
 | 
				
			||||||
 | 
					      x.foo
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    assert_nothing_raised do
 | 
				
			||||||
 | 
					      x.bar
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    y = klass.new
 | 
				
			||||||
 | 
					    assert_raise(NoMethodError) do
 | 
				
			||||||
 | 
					      y.bar
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -343,7 +343,7 @@ rb_method_call_status(rb_thread_t *th, rb_method_entry_t *me, call_type scope, V
 | 
				
			||||||
		if (self == Qundef) {
 | 
							if (self == Qundef) {
 | 
				
			||||||
		    self = th->cfp->self;
 | 
							    self = th->cfp->self;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!rb_obj_is_kind_of(self, rb_class_real(defined_class))) {
 | 
							if (!rb_obj_is_kind_of(self, defined_class)) {
 | 
				
			||||||
		    return NOEX_PROTECTED;
 | 
							    return NOEX_PROTECTED;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -623,7 +623,7 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp,
 | 
				
			||||||
		    defined_class = RBASIC(defined_class)->klass;
 | 
							    defined_class = RBASIC(defined_class)->klass;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!rb_obj_is_kind_of(cfp->self, rb_class_real(defined_class))) {
 | 
							if (!rb_obj_is_kind_of(cfp->self, defined_class)) {
 | 
				
			||||||
		    val = vm_method_missing(th, id, recv, num, blockptr, NOEX_PROTECTED);
 | 
							    val = vm_method_missing(th, id, recv, num, blockptr, NOEX_PROTECTED);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue