From f19848a1b39308a13c9f839ffd189a768e9fcdc3 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 3 Dec 2019 09:44:46 +0000 Subject: [PATCH] SW: Address Sanitization commenceth git-svn-id: https://svn.eduke32.com/eduke32@8347 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/sw/src/game.h | 4 ++-- source/sw/src/player.cpp | 6 +++--- source/sw/src/scrip2.cpp | 3 ++- source/sw/src/weapon.cpp | 43 +++++++++++++++++++++++----------------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index da5d2ad94..ab94a1f7d 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -378,8 +378,8 @@ extern char MessageOutputString[256]; #define TEST_SYNC_KEY(player, sync_num) TEST((player)->input.bits, (1 << (sync_num))) #define RESET_SYNC_KEY(player, sync_num) RESET((player)->input.bits, (1 << (sync_num))) -#define TRAVERSE_SPRITE_SECT(l, o, n) for ((o) = (l); (n) = nextspritesect[o], (o) != -1; (o) = (n)) -#define TRAVERSE_SPRITE_STAT(l, o, n) for ((o) = (l); (n) = nextspritestat[o], (o) != -1; (o) = (n)) +#define TRAVERSE_SPRITE_SECT(l, o, n) for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritesect[o], (o) != -1; (o) = (n)) +#define TRAVERSE_SPRITE_STAT(l, o, n) for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritestat[o], (o) != -1; (o) = (n)) #define TRAVERSE_CONNECT(i) for (i = connecthead; i != -1; i = connectpoint2[i]) diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 79a4f332a..f6d2a1015 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -3641,7 +3641,7 @@ void StackedWaterSplash(PLAYERp pp) updatesectorz(pp->posx, pp->posy, SPRITEp_BOS(pp->SpriteP), §num); - if (SectorIsUnderwaterArea(sectnum)) + if (sectnum >= 0 && SectorIsUnderwaterArea(sectnum)) { PlaySound(DIGI_SPLASH1, &pp->posx, &pp->posy, &pp->posz, v3df_dontpan); } @@ -4094,7 +4094,7 @@ DoPlayerWadeSuperJump(PLAYERp pp) { hitinfo.sect = wall[hitinfo.wall].nextsector; - if (labs(sector[hitinfo.sect].floorz - pp->posz) < Z(50)) + if (hitinfo.sect >= 0 && labs(sector[hitinfo.sect].floorz - pp->posz) < Z(50)) { if (Distance(pp->posx, pp->posy, hitinfo.pos.x, hitinfo.pos.y) < ((((int)pp->SpriteP->clipdist)<<2) + 256)) return TRUE; @@ -4694,7 +4694,7 @@ PlayerCanDiveNoWarp(PLAYERp pp) updatesectorz(pp->posx, pp->posy, SPRITEp_BOS(pp->SpriteP), §num); - if (SectorIsUnderwaterArea(sectnum)) + if (sectnum >= 0 && SectorIsUnderwaterArea(sectnum)) { pp->cursectnum = sectnum; pp->posz = sector[sectnum].ceilingz; diff --git a/source/sw/src/scrip2.cpp b/source/sw/src/scrip2.cpp index aa770c3c2..10a95f557 100644 --- a/source/sw/src/scrip2.cpp +++ b/source/sw/src/scrip2.cpp @@ -89,7 +89,7 @@ SWBOOL LoadScriptFile(const char *filename) size = fp.GetLength(); - scriptbuffer = (char *)AllocMem(size); + scriptbuffer = (char *)AllocMem(size+1); ASSERT(scriptbuffer != NULL); @@ -97,6 +97,7 @@ SWBOOL LoadScriptFile(const char *filename) ASSERT(readsize == size); + scriptbuffer[readsize] = '\0'; // Convert filebuffer to all upper case //Bstrupr(scriptbuffer); diff --git a/source/sw/src/weapon.cpp b/source/sw/src/weapon.cpp index fdfcd7b56..b84819017 100644 --- a/source/sw/src/weapon.cpp +++ b/source/sw/src/weapon.cpp @@ -2653,12 +2653,12 @@ STATE s_PaperShrapC[] = SWBOOL MissileHitMatch(short Weapon, short WeaponNum, short hit_sprite) { SPRITEp hsp = &sprite[hit_sprite]; - SPRITEp wp = &sprite[Weapon]; - USERp wu = User[Weapon]; if (WeaponNum <= -1) { ASSERT(Weapon >= 0); + SPRITEp wp = &sprite[Weapon]; + USERp wu = User[Weapon]; WeaponNum = wu->WeaponNum; // can be hit by SO only @@ -5760,8 +5760,6 @@ PlayerCheckDeath(PLAYERp pp, short Weapon) { SPRITEp sp = pp->SpriteP; USERp u = User[pp->PlayerSprite]; - SPRITEp wp = &sprite[Weapon]; - USERp wu = User[Weapon]; int SpawnZombie(PLAYERp pp, short); @@ -5786,6 +5784,9 @@ PlayerCheckDeath(PLAYERp pp, short Weapon) return TRUE; } + SPRITEp wp = &sprite[Weapon]; + USERp wu = User[Weapon]; + if (Weapon > -1 && (wu->ID == RIPPER_RUN_R0 || wu->ID == RIPPER2_RUN_R0)) pp->DeathType = PLAYER_DEATH_RIPPER; @@ -5828,14 +5829,14 @@ PlayerCheckDeath(PLAYERp pp, short Weapon) SWBOOL PlayerTakeDamage(PLAYERp pp, short Weapon) { + if (Weapon < 0) + return TRUE; + SPRITEp sp = pp->SpriteP; USERp u = User[pp->PlayerSprite]; SPRITEp wp = &sprite[Weapon]; USERp wu = User[Weapon]; - if (Weapon < 0) - return TRUE; - if (gNet.MultiGameType == MULTI_GAME_NONE) { // ZOMBIE special case for single play @@ -7607,9 +7608,11 @@ DoDamageTest(short Weapon) return 0; } -int -DoHitscanDamage(short Weapon, short hit_sprite) +static int DoHitscanDamage(short Weapon, uint16_t hit_sprite) { + if (hit_sprite >= MAXSPRITES) + return 0; + SPRITEp wp = &sprite[Weapon]; USERp wu = User[Weapon]; unsigned stat; @@ -10832,8 +10835,8 @@ SpawnFireballFlames(int16_t SpriteNum, int16_t enemy) { SPRITEp sp = &sprite[SpriteNum]; USERp u = User[SpriteNum]; - SPRITEp ep = &sprite[enemy]; - USERp eu = User[enemy]; + SPRITEp ep; + USERp eu; SPRITEp np; USERp nu; short New; @@ -10843,6 +10846,9 @@ SpawnFireballFlames(int16_t SpriteNum, int16_t enemy) if (enemy >= 0) { + ep = &sprite[enemy]; + eu = User[enemy]; + // test for already burned if (TEST(ep->extra, SPRX_BURNABLE) && ep->shade > 40) return -1; @@ -17843,17 +17849,18 @@ SWBOOL HitscanSpriteAdjust(short SpriteNum, short hit_wall) { SPRITEp sp = &sprite[SpriteNum]; - short w, nw, ang = sp->ang, wall_ang; + int16_t ang; int xvect,yvect; short sectnum; #if 1 - w = hit_wall; - nw = wall[w].point2; - wall_ang = NORM_ANGLE(getangle(wall[nw].x - wall[w].x, wall[nw].y - wall[w].y)); - if (hit_wall >= 0) + { + uint16_t const w = hit_wall; + uint16_t const nw = wall[hit_wall].point2; + int16_t const wall_ang = NORM_ANGLE(getangle(wall[nw].x - wall[w].x, wall[nw].y - wall[w].y)); ang = sp->ang = NORM_ANGLE(wall_ang + 512); + } else ang = sp->ang; #endif @@ -20638,13 +20645,13 @@ void QueueReset(void) SWBOOL TestDontStick(short SpriteNum, short hit_sect, short hit_wall, int hit_z) { - SPRITEp sp = &sprite[SpriteNum]; - USERp u = User[SpriteNum]; WALLp wp; if (hit_wall < 0) { ASSERT(SpriteNum>=0); + SPRITEp sp = &sprite[SpriteNum]; + USERp u = User[SpriteNum]; hit_wall = NORM_WALL(u->ret); }