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 12401f1a1..84b35efe6 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2600,14 +2600,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)); @@ -4218,23 +4222,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 efd4528af..88e6b4641 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1448,7 +1448,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 d1f760c97..848c60168 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4073,7 +4073,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 437fc98a7..f9b751ee9 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -338,6 +338,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 3efe39b9e..5faf1b291 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -551,7 +551,7 @@ static inline void I_ShutdownConsole(void){} // -//I_OutputMsg +// I_OutputMsg // void I_OutputMsg(const char *fmt, ...) { @@ -559,6 +559,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); @@ -566,6 +569,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';