Skip to content

Commit

Permalink
NODE_ASGN arguments may be 127 (CALL_MAXARGS) accidentally; fix #3559
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 1, 2017
1 parent e22f37a commit dcbfe71
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mrbgems/mruby-compiler/core/codegen.c
Expand Up @@ -792,15 +792,15 @@ attrsym(codegen_scope *s, mrb_sym a)
#define CALL_MAXARGS 127 #define CALL_MAXARGS 127


static int static int
gen_values(codegen_scope *s, node *t, int val) gen_values(codegen_scope *s, node *t, int val, int extra)
{ {
int n = 0; int n = 0;
int is_splat; int is_splat;


while (t) { while (t) {
is_splat = (intptr_t)t->car->car == NODE_SPLAT; /* splat mode */ is_splat = (intptr_t)t->car->car == NODE_SPLAT; /* splat mode */
if ( if (
n >= CALL_MAXARGS - 1 /* need to subtract one because vm.c expects an array if n == CALL_MAXARGS */ n+extra >= CALL_MAXARGS - 1 /* need to subtract one because vm.c expects an array if n == CALL_MAXARGS */
|| is_splat) { || is_splat) {
if (val) { if (val) {
if (is_splat && n == 0 && (intptr_t)t->car->cdr->car == NODE_ARRAY) { if (is_splat && n == 0 && (intptr_t)t->car->cdr->car == NODE_ARRAY) {
Expand Down Expand Up @@ -872,7 +872,7 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
idx = new_msym(s, sym); idx = new_msym(s, sym);
tree = tree->cdr->cdr->car; tree = tree->cdr->cdr->car;
if (tree) { if (tree) {
n = gen_values(s, tree->car, VAL); n = gen_values(s, tree->car, VAL, sp?1:0);
if (n < 0) { if (n < 0) {
n = noop = sendv = 1; n = noop = sendv = 1;
push(); push();
Expand Down Expand Up @@ -1632,7 +1632,7 @@ codegen(codegen_scope *s, node *tree, int val)
{ {
int n; int n;


n = gen_values(s, tree, val); n = gen_values(s, tree, val, 0);
if (n >= 0) { if (n >= 0) {
if (val) { if (val) {
pop_n(n); pop_n(n);
Expand Down Expand Up @@ -1806,7 +1806,7 @@ codegen(codegen_scope *s, node *tree, int val)
idx = new_msym(s, sym(n->cdr->car)); idx = new_msym(s, sym(n->cdr->car));
if (n->cdr->cdr->car) { if (n->cdr->cdr->car) {
int base = cursp()-1; int base = cursp()-1;
int nargs = gen_values(s, n->cdr->cdr->car->car, VAL); int nargs = gen_values(s, n->cdr->cdr->car->car, VAL, 1);


/* copy receiver and arguments */ /* copy receiver and arguments */
if (nargs >= 0) { if (nargs >= 0) {
Expand Down Expand Up @@ -1943,7 +1943,7 @@ codegen(codegen_scope *s, node *tree, int val)
if (tree) { if (tree) {
node *args = tree->car; node *args = tree->car;
if (args) { if (args) {
n = gen_values(s, args, VAL); n = gen_values(s, args, VAL, 0);
if (n < 0) { if (n < 0) {
n = noop = sendv = 1; n = noop = sendv = 1;
push(); push();
Expand Down Expand Up @@ -2020,7 +2020,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABx(OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf))); genop(s, MKOP_ABx(OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf)));
push(); push();
if (tree) { if (tree) {
n = gen_values(s, tree, VAL); n = gen_values(s, tree, VAL, 0);
if (n < 0) { if (n < 0) {
n = sendv = 1; n = sendv = 1;
push(); push();
Expand Down

0 comments on commit dcbfe71

Please sign in to comment.