From 0f83f89c9e1273a476b5fcf5e90bcfa3e5a765e8 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 8 Jun 2019 11:41:01 +0200 Subject: [PATCH] :art: Add Vararg access check --- src/emit/emit.c | 2 +- src/lib/vararg.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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); -- 2.43.0