From 701b7436dec2613c08d1818ef7102e0fce1be3f3 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Mon, 29 Dec 2025 13:11:58 -0500 Subject: [PATCH] fix some null pointer dereferences Based on https://github.com/Indev450/SRB2Kart-Saturn/commit/b0bf588c27363f192b14e2b795fa7f761fce297b and https://github.com/Indev450/SRB2Kart-Saturn/commit/67e74b5874a4edc19c504947421151eab77f307c --- src/m_misc.cpp | 9 +++++---- src/w_wad.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/m_misc.cpp b/src/m_misc.cpp index f8a106345..91b4a9a5a 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -1728,14 +1728,15 @@ void M_MinimapGenerate(void) minigen = AM_MinimapGenerate(mul); if (minigen == NULL || minigen->buf == NULL) - goto failure; + { + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create %s\n"), filepath); + return; + } M_CreateScreenShotPalette(); ret = M_SavePNG(filepath, minigen->buf, minigen->w, minigen->h, screenshot_palette); -failure: - if (minigen->buf != NULL) - free(minigen->buf); + free(minigen->buf); if (ret) { diff --git a/src/w_wad.cpp b/src/w_wad.cpp index fb5955974..18476a9d0 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -2300,11 +2300,16 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); + if (rspr == NULL) + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); + if (rspr->patches[idx] == NULL) { INT32 xpivot = 0, ypivot = 0; ptr = (patch_t *)W_CachePatchNum(num, PU_PATCH); + if (ptr == NULL) + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); // >y pivot centered // >x pivot not centered @@ -2699,6 +2704,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = (UINT8 *)W_CacheLumpNum(lumpnum, PU_LEVEL); + if (wadData == NULL) + I_Error("vres_GetMap: Invalid WadData!\n"); + filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs); i = ((wadinfo_t *)wadData)->numlumps; @@ -2716,6 +2724,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) vlumps = (virtlump_t *)Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); + // Build the lumps, skipping over empty entries. for (i = 0, realentry = 0; i < numlumps; realentry++) { @@ -2758,6 +2769,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) numlumps++; vlumps = (virtlump_t *)Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); + for (i = 0; i < numlumps; i++, lumpnum++) { vlumps[i].size = W_LumpLength(lumpnum);