From c09c38c04830c966217ae31ffa380e5029f470cf Mon Sep 17 00:00:00 2001 From: Spoike Date: Fri, 12 Aug 2005 01:17:07 +0000 Subject: [PATCH] Don't crash the engine on an otherwise legitimate progs. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1221 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/qclib/pr_edict.c | 69 ++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/engine/qclib/pr_edict.c b/engine/qclib/pr_edict.c index 707d64a29..971576e1b 100644 --- a/engine/qclib/pr_edict.c +++ b/engine/qclib/pr_edict.c @@ -2854,28 +2854,6 @@ retry: break; } } - - if (pr_progs->version == PROG_EXTENDEDVERSION && pr_progs->numbodylessfuncs) - { - s = &((char *)pr_progs)[pr_progs->ofsbodylessfuncs]; - for (i = 0; i < pr_progs->numbodylessfuncs; i++) - { - d16 = ED_FindGlobal16(progfuncs, s); - if (!d16) - Sys_Error("Progs requires \"%s\" the external function \"%s\", but the definition was stripped", filename, s); - - ((int *)glob)[d16->ofs] = PR_FindFunc(progfuncs, s, PR_ANY); - if (!((int *)glob)[d16->ofs]) - Sys_Error("Runtime-linked function %s was not found in primary progs (loading %s)", s, filename); - /* - d2 = ED_FindGlobalOfsFromProgs(progfuncs, s, 0, ev_function); - if (!d2) - Sys_Error("Runtime-linked function %s was not found in primary progs (loading %s)", s, filename); - ((int *)glob)[d16->ofs] = (*(func_t *)&pr_progstate[0].globals[*d2]); - */ - s+=strlen(s)+1; - } - } break; case 32: for (i=0 ; inumglobaldefs ; i++) @@ -2949,6 +2927,53 @@ retry: if (eval) eval->prog = progstype; + switch(current_progstate->intsize) + { + case 16: + if (pr_progs->version == PROG_EXTENDEDVERSION && pr_progs->numbodylessfuncs) + { + s = &((char *)pr_progs)[pr_progs->ofsbodylessfuncs]; + for (i = 0; i < pr_progs->numbodylessfuncs; i++) + { + d16 = ED_FindGlobal16(progfuncs, s); + if (!d16) + Sys_Error("Progs requires \"%s\" the external function \"%s\", but the definition was stripped", filename, s); + + ((int *)glob)[d16->ofs] = PR_FindFunc(progfuncs, s, PR_ANY); + if (!((int *)glob)[d16->ofs]) + Sys_Error("Runtime-linked function %s was not found in primary progs (loading %s)", s, filename); + /* + d2 = ED_FindGlobalOfsFromProgs(progfuncs, s, 0, ev_function); + if (!d2) + Sys_Error("Runtime-linked function %s was not found in primary progs (loading %s)", s, filename); + ((int *)glob)[d16->ofs] = (*(func_t *)&pr_progstate[0].globals[*d2]); + */ + s+=strlen(s)+1; + } + } + break; + case 24: + break; //cannot happen anyway. + case 32: + if (pr_progs->version == PROG_EXTENDEDVERSION && pr_progs->numbodylessfuncs) + { + s = &((char *)pr_progs)[pr_progs->ofsbodylessfuncs]; + for (i = 0; i < pr_progs->numbodylessfuncs; i++) + { + d32 = ED_FindGlobal32(progfuncs, s); + d2 = ED_FindGlobalOfsFromProgs(progfuncs, s, 0, ev_function); + if (!d2) + Sys_Error("Runtime-linked function %s was not found in existing progs", s); + if (!d32) + Sys_Error("Couldn't find def for \"%s\"", s); + ((int *)glob)[d32->ofs] = (*(func_t *)&pr_progstate[0].globals[*d2]); + + s+=strlen(s)+1; + } + } + break; + } + return true; }