From: fennecdjay Date: Sat, 8 Jun 2019 09:41:01 +0000 (+0200) Subject: :art: Add Vararg access check X-Git-Tag: nightly~2443^2~12 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=0f83f89c9e1273a476b5fcf5e90bcfa3e5a765e8;p=gwion.git :art: Add Vararg access check --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 6f7d6aac..53d96f6f 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -665,7 +665,7 @@ ANN static m_uint vararg_size(const Exp_Call* exp_call, const Vector kinds) { ANN static void emit_func_arg_vararg(const Emitter emit, const Exp_Call* exp_call) { const Instr instr = emit_add_instr(emit, VarargIni); const Vector kinds = new_vector(emit->gwion->mp); - if((instr->m_val = round2szint(vararg_size(exp_call, kinds)))) + if((instr->m_val = vararg_size(exp_call, kinds))) instr->m_val2 = (m_uint)kinds; else { instr->opcode = eRegPushImm; diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 34f4c2cb..226f81bf 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -57,6 +57,10 @@ INSTR(VarargEnd) { INSTR(VarargMember) { const struct Vararg_* arg = *(struct Vararg_**)MEM(instr->m_val); + if(instr->m_val2 != arg->k[arg->i]) { // TODO: differnciate object and primitives + free_vararg(shred->info->mp, arg); + Except(shred, "InvalidVariadicAccess"); + } for(m_uint i = 0; i < instr->m_val2; i += SZ_INT) *(m_uint*)REG(i) = *(m_uint*)(arg->d + arg->o + i); PUSH_REG(shred, instr->m_val2);