From d37ef521fbb1951ab9854c9c28be2ffbf751faa2 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 30 Oct 2011 19:46:51 +0000 Subject: [PATCH] A couple of small tweaks: - fix arg checking in checkdefs.sh - some tilenum and quote ID validation in the CON interpreter - G_DrawDigiNum and friends: eliminate redundant strlen calls git-svn-id: https://svn.eduke32.com/eduke32@2086 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/engine.c | 6 ++-- polymer/eduke32/build/src/util/checkdefs.sh | 2 ++ polymer/eduke32/source/game.c | 19 +++++------ polymer/eduke32/source/gameexec.c | 38 ++++++++++++++++++--- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index a7356e755..4564a733f 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -10719,9 +10719,10 @@ int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, in int32_t cfz1[2], cfz2[2]; // both wrt dasectnum int16_t bn[2]; -#endif Bmemset(&pendingvec, 0, sizeof(vec3_t)); // compiler-happy +#endif + Bmemset(sectbitmap, 0, (numsectors+7)>>3); #ifdef YAX_ENABLE @@ -15824,7 +15825,8 @@ int32_t setrendermode(int32_t renderer) } if (!md3postload_polymer((md3model_t *)models[i])) - OSD_Printf("INTERNAL ERROR: mdmodel %d failed postprocessing!\n", i); + OSD_Printf("INTERNAL ERROR: mdmodel %s failed postprocessing!\n", + ((md3model_t *)models[i])->head.nam); if (((md3model_t *)models[i])->head.surfs[0].geometry == NULL) OSD_Printf("INTERNAL ERROR: wtf?\n"); diff --git a/polymer/eduke32/build/src/util/checkdefs.sh b/polymer/eduke32/build/src/util/checkdefs.sh index 0fa4e122d..a6d9fc416 100755 --- a/polymer/eduke32/build/src/util/checkdefs.sh +++ b/polymer/eduke32/build/src/util/checkdefs.sh @@ -2,6 +2,7 @@ if [ -z "$1" ]; then echo 'Usage: checkdefs.sh [[] -patch]' + exit 1 fi deffn="$1" @@ -14,6 +15,7 @@ fi if [ -n "$3" ]; then if [ "$3" != "-patch" ]; then echo 'Usage: checkdefs.sh [[] -patch]' + exit 1 fi fi diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 9744066e4..e47428b72 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -922,10 +922,9 @@ static void G_DrawWeapAmounts(DukePlayer_t *p,int32_t x,int32_t y,int32_t u) static void G_DrawDigiNum(int32_t x,int32_t y,int32_t n,char s,int32_t cs) { int32_t i, j = 0, k, p, c; - char b[10]; + char b[12]; - Bsnprintf(b,10,"%d",n); - i = Bstrlen(b); + i = Bsprintf(b,"%d",n); for (k=i-1; k>=0; k--) { @@ -947,16 +946,15 @@ void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s int32_t cs,int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z) { int32_t i, j = 0, k, p, c; - char b[10]; + char b[12]; int32_t shift = (cs&ROTATESPRITE_MAX)?0:16; //ltoa(n,b,10); - Bsnprintf(b,10,"%d",n); - i = Bstrlen(b); + i = Bsprintf(b,"%d",n); for (k=i-1; k>=0; k--) { - p = starttile+*(b+k)-'0'; + p = starttile + b[k]-'0'; j += ((1+tilesizx[p])*z)>>16; } if (cs&ROTATESPRITE_MAX) j<<=16; @@ -965,7 +963,7 @@ void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s j = 0; for (k=0; k>((cs&ROTATESPRITE_MAX)?0:16)); } @@ -974,15 +972,14 @@ void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s static void G_DrawAltDigiNum(int32_t x,int32_t y,int32_t n,char s,int32_t cs) { int32_t i, j = 0, k, p, c; - char b[10]; + char b[12]; int32_t rev = (x < 0); int32_t shd = (y < 0); if (rev) x = -x; if (shd) y = -y; - Bsnprintf(b,10,"%d",n); - i = Bstrlen(b); + i = Bsprintf(b,"%d",n); for (k=i-1; k>=0; k--) { diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 1f6d4b07c..15fd921cb 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -2288,7 +2288,7 @@ nullquote: int32_t y2=scale(Gv_GetVarX(*insptr++),ydim,200); int32_t smoothratio = min(max((totalclock - ototalclock) * (65536 / 4),0),65536); #ifdef USE_OPENGL - int32_t j; + int32_t oprojhacks; #endif if (g_screenCapture) continue; @@ -2308,7 +2308,7 @@ nullquote: } #ifdef USE_OPENGL - j = glprojectionhacks; + oprojhacks = glprojectionhacks; glprojectionhacks = 0; #endif setview(x1,y1,x2,y2); @@ -2373,7 +2373,7 @@ nullquote: G_RestoreInterpolations(); G_UpdateScreenArea(); #ifdef USE_OPENGL - glprojectionhacks = j; + glprojectionhacks = oprojhacks; #endif continue; } @@ -2394,7 +2394,13 @@ nullquote: y<<=16; } - if (x < (-320)<<16 || x >= (640<<16) || y < (-200)<<16 || y >= (400<<16)) + if ((unsigned)tilenum >= MAXTILES) + { + OSD_Printf(CON_ERROR "invalid tilenum %d\n", g_errorLineNum, keyw[g_tw], tilenum); + continue; + } + + if (x < -(320<<16) || x >= (640<<16) || y < -(200<<16) || y >= (400<<16)) { OSD_Printf(CON_ERROR "invalid coordinates: %d, %d\n",g_errorLineNum, keyw[g_tw], x, y); continue; @@ -2416,6 +2422,18 @@ nullquote: int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); int32_t z = (tw == CON_GAMETEXTZ) ? Gv_GetVarX(*insptr++) : 65536; + if (tilenum < 0 || tilenum+255 >= MAXTILES) + { + OSD_Printf(CON_ERROR "invalid base tilenum %d\n", g_errorLineNum, keyw[g_tw], tilenum); + continue; + } + + if ((unsigned)q >= MAXQUOTES) + { + OSD_Printf(CON_ERROR "invalid quote ID %d\n", g_errorLineNum, keyw[g_tw], q); + continue; + } + if ((ScriptQuotes[q] == NULL)) { OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],q); @@ -2440,6 +2458,12 @@ nullquote: int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); int32_t z = (tw == CON_DIGITALNUMBERZ) ? Gv_GetVarX(*insptr++) : 65536; + if (tilenum < 0 || tilenum+'9' >= MAXTILES) + { + OSD_Printf(CON_ERROR "invalid base tilenum %d\n", g_errorLineNum, keyw[g_tw], tilenum); + continue; + } + G_DrawTXDigiNumZ(tilenum,x,y,q,shade,pal,orientation,x1,y1,x2,y2,z); continue; } @@ -2450,6 +2474,12 @@ nullquote: int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), q=Gv_GetVarX(*insptr++); int32_t shade=Gv_GetVarX(*insptr++), pal=Gv_GetVarX(*insptr++); + if ((unsigned)q >= MAXQUOTES) + { + OSD_Printf(CON_ERROR "invalid quote ID %d\n", g_errorLineNum, keyw[g_tw], q); + continue; + } + if ((ScriptQuotes[q] == NULL)) { OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],q);