]> Nishi Git Mirror - gwion.git/commitdiff
:art: Add Vararg access check
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sat, 8 Jun 2019 09:41:01 +0000 (11:41 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sat, 8 Jun 2019 09:41:01 +0000 (11:41 +0200)
src/emit/emit.c
src/lib/vararg.c

index 6f7d6aacc53086154ff5e9dc89593e46b683f49e..53d96f6f3af5d754a78dd0c58e7f67011674e919 100644 (file)
@@ -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;
index 34f4c2cb0ac5e9a33f01c51803751f7adfbe94f7..226f81bf22d23142184a9d16b98443cc105d4f64 100644 (file)
@@ -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);