mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (rb_call), eval_method.ci (rb_add_method, rb_alias),
insnhelper.ci (vm_call_method): fix to save safelevel for method node. * include/ruby/node.h: ditto. * bootstraptest/test_method.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e5d5f5a61a
commit
b982cff67c
6 changed files with 107 additions and 32 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Fri Aug 17 21:20:44 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* eval.c (rb_call), eval_method.ci (rb_add_method, rb_alias),
|
||||||
|
insnhelper.ci (vm_call_method): fix to save safelevel for
|
||||||
|
method node.
|
||||||
|
|
||||||
|
* include/ruby/node.h: ditto.
|
||||||
|
|
||||||
|
* bootstraptest/test_method.rb: add a test for above.
|
||||||
|
|
||||||
Fri Aug 17 16:02:50 2007 Koichi Sasada <ko1@atdot.net>
|
Fri Aug 17 16:02:50 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* thread.c (rb_thread_terminate_all): fix to ignore
|
* thread.c (rb_thread_terminate_all): fix to ignore
|
||||||
|
|
|
@ -860,5 +860,49 @@ class C0; def m *args; [:C0_m, args]; end; end
|
||||||
class C1 < C0; def m a, o=:o; super; end; end
|
class C1 < C0; def m a, o=:o; super; end; end
|
||||||
; C1.new.m 1, 2}
|
; C1.new.m 1, 2}
|
||||||
|
|
||||||
|
assert_equal %q{[:ok, :ok, :ok, :ok, :ok, :ok, :ng, :ng]}, %q{
|
||||||
|
$ans = []
|
||||||
|
class Foo
|
||||||
|
def m
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias funcall send unless defined? funcall
|
||||||
|
|
||||||
|
c1 = c2 = nil
|
||||||
|
|
||||||
|
lambda{
|
||||||
|
$SAFE = 4
|
||||||
|
c1 = Class.new{
|
||||||
|
def m
|
||||||
|
end
|
||||||
|
}
|
||||||
|
c2 = Class.new(Foo){
|
||||||
|
alias mm m
|
||||||
|
}
|
||||||
|
}.call
|
||||||
|
|
||||||
|
def test
|
||||||
|
begin
|
||||||
|
yield
|
||||||
|
rescue SecurityError
|
||||||
|
$ans << :ok
|
||||||
|
else
|
||||||
|
$ans << :ng
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
o1 = c1.new
|
||||||
|
o2 = c2.new
|
||||||
|
|
||||||
|
test{o1.m}
|
||||||
|
test{o2.mm}
|
||||||
|
test{o1.send :m}
|
||||||
|
test{o2.send :mm}
|
||||||
|
test{o1.funcall :m}
|
||||||
|
test{o2.funcall :mm}
|
||||||
|
test{o1.method(:m).call}
|
||||||
|
test{o2.method(:mm).call}
|
||||||
|
$ans
|
||||||
|
}
|
||||||
|
|
||||||
|
|
41
eval.c
41
eval.c
|
@ -1343,6 +1343,7 @@ rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope)
|
||||||
int noex;
|
int noex;
|
||||||
ID id = mid;
|
ID id = mid;
|
||||||
struct cache_entry *ent;
|
struct cache_entry *ent;
|
||||||
|
rb_thread_t *th = GET_THREAD();
|
||||||
|
|
||||||
if (!klass) {
|
if (!klass) {
|
||||||
rb_raise(rb_eNotImpError,
|
rb_raise(rb_eNotImpError,
|
||||||
|
@ -1351,6 +1352,7 @@ rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope)
|
||||||
}
|
}
|
||||||
/* is it in the method cache? */
|
/* is it in the method cache? */
|
||||||
ent = cache + EXPR1(klass, mid);
|
ent = cache + EXPR1(klass, mid);
|
||||||
|
|
||||||
if (ent->mid == mid && ent->klass == klass) {
|
if (ent->mid == mid && ent->klass == klass) {
|
||||||
if (!ent->method)
|
if (!ent->method)
|
||||||
return method_missing(recv, mid, argc, argv,
|
return method_missing(recv, mid, argc, argv,
|
||||||
|
@ -1372,23 +1374,31 @@ rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope)
|
||||||
return method_missing(recv, mid, argc, argv,
|
return method_missing(recv, mid, argc, argv,
|
||||||
scope == 2 ? NOEX_VCALL : 0);
|
scope == 2 ? NOEX_VCALL : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (mid != missing) {
|
if (mid != missing) {
|
||||||
/* receiver specified form for private method */
|
/* receiver specified form for private method */
|
||||||
if (((noex & NOEX_MASK) & NOEX_PRIVATE) && scope == 0) {
|
if (UNLIKELY(noex)) {
|
||||||
return method_missing(recv, mid, argc, argv, NOEX_PRIVATE);
|
if (((noex & NOEX_MASK) & NOEX_PRIVATE) && scope == 0) {
|
||||||
}
|
return method_missing(recv, mid, argc, argv, NOEX_PRIVATE);
|
||||||
|
|
||||||
/* self must be kind of a specified form for protected method */
|
|
||||||
if (((noex & NOEX_MASK) & NOEX_PROTECTED) && scope == 0) {
|
|
||||||
VALUE defined_class = klass;
|
|
||||||
|
|
||||||
if (TYPE(defined_class) == T_ICLASS) {
|
|
||||||
defined_class = RBASIC(defined_class)->klass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rb_obj_is_kind_of(rb_frame_self(),
|
/* self must be kind of a specified form for protected method */
|
||||||
rb_class_real(defined_class))) {
|
if (((noex & NOEX_MASK) & NOEX_PROTECTED) && scope == 0) {
|
||||||
return method_missing(recv, mid, argc, argv, NOEX_PROTECTED);
|
VALUE defined_class = klass;
|
||||||
|
|
||||||
|
if (TYPE(defined_class) == T_ICLASS) {
|
||||||
|
defined_class = RBASIC(defined_class)->klass;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rb_obj_is_kind_of(rb_frame_self(),
|
||||||
|
rb_class_real(defined_class))) {
|
||||||
|
return method_missing(recv, mid, argc, argv, NOEX_PROTECTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NOEX_SAFE(noex) > th->safe_level) {
|
||||||
|
rb_raise(rb_eSecurityError, "calling insecure method: %s", rb_id2name(mid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1403,9 +1413,8 @@ rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope)
|
||||||
//level++;
|
//level++;
|
||||||
//printf("%s with %d args\n", rb_id2name(mid), argc);
|
//printf("%s with %d args\n", rb_id2name(mid), argc);
|
||||||
*/
|
*/
|
||||||
val =
|
val = vm_call0(th, klass, recv, mid, id, argc, argv, body,
|
||||||
vm_call0(GET_THREAD(), klass, recv, mid, id, argc, argv, body,
|
noex & NOEX_NOSUPER);
|
||||||
noex & NOEX_NOSUPER);
|
|
||||||
/*
|
/*
|
||||||
//level--;
|
//level--;
|
||||||
//for(i=0; i<level; i++){printf(" ");}
|
//for(i=0; i<level; i++){printf(" ");}
|
||||||
|
|
|
@ -132,7 +132,7 @@ rb_add_method(VALUE klass, ID mid, NODE * node, int noex)
|
||||||
* nd_cnt : alias count // (3)
|
* nd_cnt : alias count // (3)
|
||||||
*/
|
*/
|
||||||
if (node) {
|
if (node) {
|
||||||
body = NEW_FBODY(NEW_METHOD(node, klass, noex), 0);
|
body = NEW_FBODY(NEW_METHOD(node, klass, NOEX_WITH_SAFE(noex)), 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
body = 0;
|
body = 0;
|
||||||
|
@ -580,7 +580,7 @@ rb_alias(VALUE klass, ID name, ID def)
|
||||||
(st_data_t) NEW_FBODY(
|
(st_data_t) NEW_FBODY(
|
||||||
NEW_METHOD(orig_fbody->nd_body->nd_body,
|
NEW_METHOD(orig_fbody->nd_body->nd_body,
|
||||||
orig_fbody->nd_body->nd_clss,
|
orig_fbody->nd_body->nd_clss,
|
||||||
orig_fbody->nd_body->nd_noex), def));
|
NOEX_WITH_SAFE(orig_fbody->nd_body->nd_noex)), def));
|
||||||
|
|
||||||
rb_clear_cache_by_id(name);
|
rb_clear_cache_by_id(name);
|
||||||
|
|
||||||
|
|
|
@ -484,6 +484,10 @@ enum ruby_node_flags {
|
||||||
#define NOEX_SUPER 0x20
|
#define NOEX_SUPER 0x20
|
||||||
#define NOEX_VCALL 0x40
|
#define NOEX_VCALL 0x40
|
||||||
|
|
||||||
|
#define NOEX_SAFE(n) (((n) >> 8) & 0x0F)
|
||||||
|
#define NOEX_WITH(n, s) ((s << 8) | n)
|
||||||
|
#define NOEX_WITH_SAFE(n) NOEX_WITH(n, rb_safe_level())
|
||||||
|
|
||||||
VALUE rb_parser_new(void);
|
VALUE rb_parser_new(void);
|
||||||
VALUE rb_parser_end_seen_p(VALUE);
|
VALUE rb_parser_end_seen_p(VALUE);
|
||||||
|
|
||||||
|
|
|
@ -487,23 +487,31 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp,
|
||||||
val = vm_method_missing(th, id, recv, num, blockptr, stat);
|
val = vm_method_missing(th, id, recv, num, blockptr, stat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!(flag & VM_CALL_FCALL_BIT) &&
|
else if (UNLIKELY(mn->nd_noex)) {
|
||||||
(mn->nd_noex & NOEX_MASK) & NOEX_PRIVATE) {
|
if (!(flag & VM_CALL_FCALL_BIT) &&
|
||||||
int stat = NOEX_PRIVATE;
|
(mn->nd_noex & NOEX_MASK) & NOEX_PRIVATE) {
|
||||||
if (flag & VM_CALL_VCALL_BIT) {
|
int stat = NOEX_PRIVATE;
|
||||||
stat |= NOEX_VCALL;
|
if (flag & VM_CALL_VCALL_BIT) {
|
||||||
|
stat |= NOEX_VCALL;
|
||||||
|
}
|
||||||
|
val = vm_method_missing(th, id, recv, num, blockptr, stat);
|
||||||
}
|
}
|
||||||
val = vm_method_missing(th, id, recv, num, blockptr, stat);
|
else if ((mn->nd_noex & NOEX_MASK) & NOEX_PROTECTED) {
|
||||||
}
|
VALUE defined_class = mn->nd_clss;
|
||||||
else if ((mn->nd_noex & NOEX_MASK) & NOEX_PROTECTED) {
|
|
||||||
VALUE defined_class = mn->nd_clss;
|
|
||||||
|
|
||||||
if (TYPE(defined_class) == T_ICLASS) {
|
if (TYPE(defined_class) == T_ICLASS) {
|
||||||
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))) {
|
||||||
|
val = vm_method_missing(th, id, recv, num, blockptr, NOEX_PROTECTED);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
goto normal_method_dispatch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (NOEX_SAFE(mn->nd_noex) > th->safe_level) {
|
||||||
if (!rb_obj_is_kind_of(cfp->self, rb_class_real(defined_class))) {
|
rb_raise(rb_eSecurityError, "calling insecure method: %s", rb_id2name(id));
|
||||||
val = vm_method_missing(th, id, recv, num, blockptr, NOEX_PROTECTED);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
goto normal_method_dispatch;
|
goto normal_method_dispatch;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue