* proc.c (rb_proc_call, rb_node_arity, bmcall, curry): checks
overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
886214bc01
commit
4fc5c89700
@ -1,6 +1,7 @@
|
|||||||
Sat Mar 14 18:05:08 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Mar 14 18:18:08 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* proc.c (rb_proc_call): checks overflow.
|
* proc.c (rb_proc_call, rb_node_arity, bmcall, curry): checks
|
||||||
|
overflow.
|
||||||
|
|
||||||
* proc.c (rb_proc_parameters): unnamed_parameters() expects in
|
* proc.c (rb_proc_parameters): unnamed_parameters() expects in
|
||||||
not VALUE.
|
not VALUE.
|
||||||
|
39
proc.c
39
proc.c
@ -526,20 +526,28 @@ proc_call(int argc, VALUE *argv, VALUE procval)
|
|||||||
argc, argv, blockptr);
|
argc, argv, blockptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_proc_call(VALUE self, VALUE args)
|
|
||||||
{
|
|
||||||
long argc = RARRAY_LEN(args);
|
|
||||||
rb_proc_t *proc;
|
|
||||||
GetProcPtr(self, proc);
|
|
||||||
#if SIZEOF_LONG > SIZEOF_INT
|
#if SIZEOF_LONG > SIZEOF_INT
|
||||||
|
static inline int
|
||||||
|
check_argc(long argc)
|
||||||
|
{
|
||||||
if (argc > INT_MAX || argc < 0) {
|
if (argc > INT_MAX || argc < 0) {
|
||||||
rb_raise(rb_eArgError, "too many arguments (%lu)",
|
rb_raise(rb_eArgError, "too many arguments (%lu)",
|
||||||
(unsigned long)argc);
|
(unsigned long)argc);
|
||||||
}
|
}
|
||||||
|
return (int)argc;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define check_argc(argc) (argc)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_proc_call(VALUE self, VALUE args)
|
||||||
|
{
|
||||||
|
long argc = ;
|
||||||
|
rb_proc_t *proc;
|
||||||
|
GetProcPtr(self, proc);
|
||||||
return rb_vm_invoke_proc(GET_THREAD(), proc, proc->block.self,
|
return rb_vm_invoke_proc(GET_THREAD(), proc, proc->block.self,
|
||||||
(int)argc, RARRAY_PTR(args), 0);
|
check_argc(RARRAY_LEN(args)), RARRAY_PTR(args), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
@ -850,7 +858,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
|
|||||||
rb_print_undef(rclass, oid, 0);
|
rb_print_undef(rclass, oid, 0);
|
||||||
}
|
}
|
||||||
if (scope && (body->nd_noex & NOEX_MASK) != NOEX_PUBLIC) {
|
if (scope && (body->nd_noex & NOEX_MASK) != NOEX_PUBLIC) {
|
||||||
rb_print_undef(rclass, oid, (body->nd_noex & NOEX_MASK));
|
rb_print_undef(rclass, oid, (int)(body->nd_noex & NOEX_MASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
klass = body->nd_clss;
|
klass = body->nd_clss;
|
||||||
@ -1418,7 +1426,7 @@ rb_node_arity(NODE* body)
|
|||||||
case NODE_CFUNC:
|
case NODE_CFUNC:
|
||||||
if (body->nd_argc < 0)
|
if (body->nd_argc < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return body->nd_argc;
|
return check_argc(body->nd_argc);
|
||||||
case NODE_ZSUPER:
|
case NODE_ZSUPER:
|
||||||
return -1;
|
return -1;
|
||||||
case NODE_ATTRSET:
|
case NODE_ATTRSET:
|
||||||
@ -1630,13 +1638,19 @@ static VALUE
|
|||||||
bmcall(VALUE args, VALUE method)
|
bmcall(VALUE args, VALUE method)
|
||||||
{
|
{
|
||||||
volatile VALUE a;
|
volatile VALUE a;
|
||||||
|
VALUE ret;
|
||||||
|
int argc;
|
||||||
|
|
||||||
if (CLASS_OF(args) != rb_cArray) {
|
if (CLASS_OF(args) != rb_cArray) {
|
||||||
args = rb_ary_new3(1, args);
|
args = rb_ary_new3(1, args);
|
||||||
|
argc = 1;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
argc = check_argc(RARRAY_LEN(argc));
|
||||||
|
}
|
||||||
|
ret = rb_method_call(argc, RARRAY_PTR(a), method);
|
||||||
a = args;
|
a = args;
|
||||||
return rb_method_call(RARRAY_LEN(a), RARRAY_PTR(a), method);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
@ -1773,7 +1787,8 @@ curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc)
|
|||||||
return arity;
|
return arity;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_proc_call_with_block(proc, RARRAY_LEN(passed), RARRAY_PTR(passed), passed_proc);
|
return rb_proc_call_with_block(proc, check_argc(RARRAY_LEN(passed)),
|
||||||
|
RARRAY_PTR(passed), passed_proc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user