From c2458c61cb886c769acf6155c7e63296e6205953 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Wed, 16 Oct 2019 09:50:12 +0000 Subject: [PATCH] changed MOO_STACK_PUSH to check process stack overflow --- moo/lib/exec.c | 2 +- moo/lib/moo.h | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 6b30c6a..5c096e9 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -6392,7 +6392,7 @@ static int __execute (moo_t* moo) END_DISPATCH_LOOP() - return 0; + return (moo->abort_req <= -1)? -1: 0; } int moo_execute (moo_t* moo) diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 6d0a5db..f517006 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -113,7 +113,7 @@ enum moo_option_dflval_t MOO_DFL_LOG_MAXCAPA = MOO_LOG_CAPA_ALIGN * 16, MOO_DFL_SYMTAB_SIZE = 5000, MOO_DFL_SYSDIC_SIZE = 5000, - MOO_DFL_PROCSTK_SIZE = 5000 + MOO_DFL_PROCSTK_SIZE = 1000 }; typedef enum moo_option_dflval_t moo_option_dflval_t; @@ -1731,11 +1731,19 @@ struct moo_t }; /* TODO: proper stack bound check when pushing */ +/*MOO_ASSERT (moo, (moo)->sp < (moo_ooi_t)(MOO_OBJ_GET_SIZE((moo)->processor->active) - MOO_PROCESS_NAMED_INSTVARS)); */ #define MOO_STACK_PUSH(moo,v) \ do { \ (moo)->sp = (moo)->sp + 1; \ - MOO_ASSERT (moo, (moo)->sp < (moo_ooi_t)(MOO_OBJ_GET_SIZE((moo)->processor->active) - MOO_PROCESS_NAMED_INSTVARS)); \ - MOO_STORE_OOP (moo, &(moo)->processor->active->stack[(moo)->sp], v); \ + if ((moo)->sp >= (moo_ooi_t)(MOO_OBJ_GET_SIZE((moo)->processor->active) - MOO_PROCESS_NAMED_INSTVARS)) \ + { \ + moo_seterrbfmt (moo, MOO_EOOMEM, "process stack overflow"); \ + (moo)->abort_req = -1; \ + } \ + else \ + { \ + MOO_STORE_OOP (moo, &(moo)->processor->active->stack[(moo)->sp], v); \ + } \ } while(0) #define MOO_STACK_GET(moo,v_sp) ((moo)->processor->active->stack[v_sp])