add overflow guards to some global stacks (or value pools)

This commit is contained in:
Yuichi Nishiwaki 2013-11-22 06:35:51 -08:00
parent 23b806cc41
commit 0a521c2314
2 changed files with 9 additions and 0 deletions

View File

@ -407,6 +407,9 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
} }
pidx = pic->plen++; pidx = pic->plen++;
if (pidx >= pic->pcapa) {
pic_abort(pic, "constant pool overflow");
}
pic->pool[pidx] = pic_car(pic, pic_cdr(pic, obj)); pic->pool[pidx] = pic_car(pic, pic_cdr(pic, obj));
irep->code[irep->clen].insn = OP_PUSHCONST; irep->code[irep->clen].insn = OP_PUSHCONST;
irep->code[irep->clen].u.i = pidx; irep->code[irep->clen].u.i = pidx;
@ -640,6 +643,9 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
case PIC_TT_BLOB: { case PIC_TT_BLOB: {
int pidx; int pidx;
pidx = pic->plen++; pidx = pic->plen++;
if (pidx >= pic->pcapa) {
pic_abort(pic, "constant pool overflow");
}
pic->pool[pidx] = obj; pic->pool[pidx] = obj;
irep->code[irep->clen].insn = OP_PUSHCONST; irep->code[irep->clen].insn = OP_PUSHCONST;
irep->code[irep->clen].u.i = pidx; irep->code[irep->clen].u.i = pidx;

View File

@ -20,6 +20,9 @@ define_macro(pic_state *pic, const char *name, struct pic_proc *macro)
int idx; int idx;
idx = pic->mlen++; idx = pic->mlen++;
if (idx >= pic->mcapa) {
pic_abort(pic, "macro table overflow");
}
pic->macros[idx] = macro; pic->macros[idx] = macro;
xh_put(pic->global_tbl, name, ~idx); xh_put(pic->global_tbl, name, ~idx);
} }