From 0ee7bb06eada573cbcd782d2ae06217ade9d65aa Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 19 Aug 2009 06:14:04 +0000 Subject: [PATCH] progs: require the last statement to be GOTO, DONE or RETURN. Ensures the statement pointer can never fall out of the progs. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9125 d7cf8633-e32d-0410-b094-e92efae38249 --- prvm_edict.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prvm_edict.c b/prvm_edict.c index 5da0a8fb..b5120522 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1920,6 +1920,20 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required break; } } + if(prog->progs->numstatements < 1) + { + PRVM_ERROR("PRVM_LoadProgs: empty program in %s", PRVM_NAME); + } + else switch(prog->statements[prog->progs->numstatements - 1].op) + { + case OP_RETURN: + case OP_GOTO: + case OP_DONE: + break; + default: + PRVM_ERROR("PRVM_LoadProgs: program may fall off the edge (does not end with RETURN, GOTO or DONE) in %s", PRVM_NAME); + break; + } PRVM_LoadLNO(filename); -- 2.39.2