Skip to content

Commit

Permalink
configuration.cpp: Additional sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 4, 2023
1 parent 93be7f5 commit 545da52
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,16 @@ bool saveConfig()
auto iniSetString = [&iniGeneral](const std::string& key, const std::string& value) {
iniGeneral[key] = value;
};
auto iniSetFromCString = [&iniGeneral](const std::string& key, const char* value, size_t maxLength) {
std::string strVal;
if (value)
{
size_t len = strnlen(value, maxLength);
ASSERT(len < maxLength, "Input c-string value (for key: %s) appears to be missing null-terminator?", key.c_str());
strVal.assign(value, len);
}
iniGeneral[key] = strVal;
};

// //////////////////////////
// voicevol, fxvol and cdvol
Expand Down Expand Up @@ -730,7 +740,7 @@ bool saveConfig()
iniSetBool("PauseOnFocusLoss", war_GetPauseOnFocusLoss());
iniSetString("autoratingUrlV2", getAutoratingUrl());
iniSetBool("autorating", getAutoratingEnable());
iniSetString("masterserver_name", NETgetMasterserverName());
iniSetFromCString("masterserver_name", NETgetMasterserverName(), 255);
iniSetInteger("masterserver_port", (int)NETgetMasterserverPort());
iniSetString("server_name", mpGetServerName());
if (!netGameserverPortOverride) // do not save the config port setting if there's a command-line override
Expand All @@ -752,7 +762,7 @@ bool saveConfig()
{
if (bMultiPlayer && NetPlay.bComms)
{
iniSetString("gameName", game.name); // last hosted game
iniSetFromCString("gameName", game.name, 128); // last hosted game
war_setMPInactivityMinutes(game.inactivityMinutes);
war_setMPGameTimeLimitMinutes(game.gameTimeLimitMinutes);
war_setMPPlayerLeaveMode(game.playerLeaveMode);
Expand All @@ -761,15 +771,15 @@ bool saveConfig()
auto currentSpectatorSlotInfo = SpectatorInfo::currentNetPlayState();
war_setMPopenSpectatorSlots(currentSpectatorSlotInfo.totalSpectatorSlots);
}
iniSetString("mapName", game.map); // map name
iniSetFromCString("mapName", game.map, 128); // map name
iniSetString("mapHash", game.hash.toString()); // map hash
iniSetInteger("maxPlayers", (int)game.maxPlayers); // maxPlayers
iniSetInteger("powerLevel", game.power); // power
iniSetInteger("base", game.base); // size of base
iniSetInteger("alliance", (int)game.alliance); // allow alliances
iniSetInteger("newScavengers", game.scavengers);
}
iniSetString("playerName", (char *)sPlayer); // player name
iniSetFromCString("playerName", (char *)sPlayer, 128); // player name
}
iniSetInteger("colourMP", war_getMPcolour());
iniSetInteger("inactivityMinutesMP", war_getMPInactivityMinutes());
Expand Down

0 comments on commit 545da52

Please sign in to comment.