From 5289027272dce5cbd2179da4427a1feeb63476f1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 22 Oct 2025 15:32:38 +0200 Subject: [PATCH 1/4] uninline ctf resynch stuff this wont ever be used and just makes lto and others complain occasionally (maybe frenmod uses ctf? forgor) --- src/d_clisrv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a62ebde7c..61afc0eb7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -823,7 +823,7 @@ static void resynch_read_player(resynch_pak *rsp) P_SetThingPosition(players[i].mo); } -static inline void resynch_write_ctf(resynchend_pak *rst) +static void resynch_write_ctf(resynchend_pak *rst) { mobj_t *mflag; UINT8 i, j; @@ -863,7 +863,7 @@ static inline void resynch_write_ctf(resynchend_pak *rst) } } -static inline void resynch_read_ctf(resynchend_pak *p) +static void resynch_read_ctf(resynchend_pak *p) { UINT8 i; From f74980027613ade10f50fa4c4dfa9ad81e9fde28 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 22 Oct 2025 15:33:09 +0200 Subject: [PATCH 2/4] fix playersetup skin speen reading out of bounds reported by ubsan --- src/m_menu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 6822dd499..e9915cb9c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -8279,12 +8279,12 @@ static void M_DrawSetupMultiPlayerMenu(void) sprframe = &sprdef->spriteframes[frame]; - //minenice's speen css, it's a piece of shit but hey + // minenice's speen css, it's a piece of shit but hey speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; - //this is a very shitty solution for checking if a sprite needs flipping - //but it works - if ((sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe]) && (speenframe > 4)) + // this is a very shitty solution for checking if a sprite needs flipping + // but it works + if ((speenframe > 4) && (sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe])) flags = V_FLIP; // This sprite is left/right flipped! patch = (patch_t *)W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); From e5bae89d0f716de6f1e52bcafb2d855f26179818 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 22 Oct 2025 15:34:24 +0200 Subject: [PATCH 3/4] fix namescrollbuf and mapmusic.name copies ensure those are properly null terminated as reported by ubsan --- src/m_menu.c | 8 ++++++-- src/p_spec.c | 3 +-- src/w_wad.c | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index e9915cb9c..a7be33c42 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7179,17 +7179,21 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) namescroll = 0; } - if (renderisnewtic) namescroll++; + if (renderisnewtic) + namescroll++; char *addonname = wadfiles[mapwads[cv_nextmap.value-1]]->filename; INT32 len; INT32 charlimit = min((size_t)(21 + (dupadjust/5)), sizeof(namescrollbuf)-1); + nameonly(addonname); len = strlen(addonname); + if (len > charlimit) M_ScrollString(addonname, len, namescrollbuf, charlimit, namescroll); else - strncpy(namescrollbuf, addonname, sizeof(namescrollbuf)); + strncpy(namescrollbuf, addonname, sizeof(namescrollbuf) - 1); + V_DrawThinString(x+w+5, y+i-8, V_TRANSLUCENT|MENUCAPS, namescrollbuf); // variable reuse... } diff --git a/src/p_spec.c b/src/p_spec.c index cf2ca3e3e..e7b032131 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2091,8 +2091,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Change the music and apply position/fade operations else { - strncpy(mapmusic.name, sides[line->sidenum[0]].text, 7); - mapmusic.name[6] = 0; + strlcpy(mapmusic.name, sides[line->sidenum[0]].text, sizeof(mapmusic.name)); mapmusic.flags = tracknum & MUSIC_TRACKMASK; if (!(line->flags & ML_BLOCKMONSTERS)) diff --git a/src/w_wad.c b/src/w_wad.c index 1cfb3f616..95992fb42 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -261,7 +261,7 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum) sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname); name[length] = '\0'; - CONS_Printf(M_GetText("Loading SOC from %s\n"), name); + CONS_Printf("Loading SOC from %s\n", name); DEH_LoadDehackedLumpPwad(wadnum, posStart); free(name); } From 5f394cd938a89685ad1dfa20404363b626a7b101 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 22 Oct 2025 16:02:24 +0200 Subject: [PATCH 4/4] handle more memory allocation failure cases reported with -Wformat-overflow --- src/command.c | 2 ++ src/d_netcmd.c | 23 ++++++++++++++++++----- src/dedicated/i_system.c | 2 +- src/g_game.c | 4 ++++ src/lua_script.c | 4 ++++ src/sdl/i_system.cpp | 9 ++++++++- src/w_wad.c | 6 ++++++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/command.c b/src/command.c index 47bd521b0..463325e60 100644 --- a/src/command.c +++ b/src/command.c @@ -938,6 +938,8 @@ static void COM_Find_f(void) } help = COM_Argv(1); + if (!help) + return; helplen = strlen(help); CONS_Printf("\x82""Variables:\n"); matchesany = false; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 65dd1d4cf..d62be9daa 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2596,14 +2596,18 @@ ConcatCommandArgv (int start, int end) size += strlen(COM_Argv(i)) + 1; } - final = ZZ_Alloc(size); - p = final; + p = final = ZZ_Alloc(size); + + if (!p) + I_Error("ConcatCommandArgv: Out of memory!\n"); --end;/* handle the final argument separately */ + for (i = start; i < end; ++i) { p += sprintf(p, "%s ", COM_Argv(i)); } + /* at this point "end" is actually the last argument's position */ strcpy(p, COM_Argv(end)); @@ -4214,23 +4218,32 @@ static void Command_MotD_f(void) mymotd = Z_Malloc(sizeof(motd), PU_STATIC, NULL); - strlcpy(mymotd, COM_Argv(1), sizeof motd); + if (!mymotd) + return; + //I_Error("Command_MotD_f: Out of memory!\n"); // idk if this aint a bit too much lel + + strlcpy(mymotd, COM_Argv(1), sizeof(motd)); + for (i = 2; i < j; i++) { - strlcat(mymotd, " ", sizeof motd); - strlcat(mymotd, COM_Argv(i), sizeof motd); + strlcat(mymotd, " ", sizeof(motd)); + strlcat(mymotd, COM_Argv(i), sizeof(motd)); } // Disallow non-printing characters and semicolons. for (i = 0; mymotd[i] != '\0'; i++) + { if (!isprint(mymotd[i]) || mymotd[i] == ';') { Z_Free(mymotd); return; } + } if ((netgame || multiplayer) && client) + { SendNetXCmd(XD_SETMOTD, mymotd, i); // send the actual size of the motd string, not the full buffer's size + } else { strcpy(motd, mymotd); diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 865ae4584..78f265e2a 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1442,7 +1442,7 @@ static INT32 errorcount = 0; */ static boolean shutdowning = false; -void I_Error(const char *error, ...) +FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) { va_list argptr; char buffer[8192]; diff --git a/src/g_game.c b/src/g_game.c index 5c984ad87..796c154d5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4061,7 +4061,11 @@ char *G_BuildMapTitle(INT32 mapnum) title = Z_Malloc(len, PU_STATIC, NULL); + if (!title) + return NULL; + sprintf(title, "%s", mapheaderinfo[mapnum-1]->lvlttl); + if (zonetext) sprintf(title + strlen(title), " %s", zonetext); if (actnum) sprintf(title + strlen(title), " %s", actnum); } diff --git a/src/lua_script.c b/src/lua_script.c index 723624ee2..e59841940 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -288,6 +288,10 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump) lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump]; len += 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name name = malloc(len+1); + + if (!name) + I_Error("LUA_LoadLump: Out of memory!\n"); + sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->fullname); name[len] = '\0'; } diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 2663887d6..4e9e54d72 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -545,7 +545,7 @@ static inline void I_ShutdownConsole(void){} // -//I_OutputMsg +// I_OutputMsg // void I_OutputMsg(const char *fmt, ...) { @@ -553,6 +553,9 @@ void I_OutputMsg(const char *fmt, ...) char *txt; va_list argptr; + if (!fmt) + return; + va_start(argptr,fmt); len = vsnprintf(NULL, 0, fmt, argptr); va_end(argptr); @@ -560,6 +563,10 @@ void I_OutputMsg(const char *fmt, ...) return; txt = static_cast(malloc(len+1)); + + if (!txt) + I_Error("I_OutputMsg: Out of memory!\n"); + va_start(argptr,fmt); vsprintf(txt, fmt, argptr); va_end(argptr); diff --git a/src/w_wad.c b/src/w_wad.c index 95992fb42..756dee4a6 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -259,6 +259,9 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum) size_t length = len + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name char *name = malloc(length + 1); + if (!name) + I_Error("W_LoadDehackedLumpsPK3: Out of memory!\n"); + sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname); name[length] = '\0'; CONS_Printf("Loading SOC from %s\n", name); @@ -292,6 +295,9 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum) size_t length = len + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name char *name = malloc(length + 1); + if (!name) + I_Error("W_LoadDehackedLumps: Out of memory!\n"); + sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->fullname); name[length] = '\0';