Prevent the lobby gamelist from breaking entirely if a gamestanza contains an empty or invalid mod version JSON string (refs eca956a513).

Catch all JSON SyntaxError exceptions in JS (refs d7d0a7f869).
The C++ ParseJSON function already catches exceptions and the resulting
errors can't trigger a denial of service.

Differential Revision: https://code.wildfiregames.com/D1479
Based on patch by: Imarok
Reviewed by: Imarok
Comments By: Itms
This was SVN commit r21827.
This commit is contained in:
elexis 2018-05-27 13:47:18 +00:00
parent 788ca1f69d
commit 4cefb286f4
2 changed files with 21 additions and 5 deletions

View file

@ -87,7 +87,13 @@ function playerDataToStringifiedTeamList(playerData)
function stringifiedTeamListToPlayerData(stringifiedTeamList)
{
let teamList = JSON.parse(unescapeText(stringifiedTeamList));
let teamList = {};
try
{
teamList = JSON.parse(unescapeText(stringifiedTeamList));
}
catch (e) {}
let playerData = [];
for (let team in teamList)
@ -171,12 +177,13 @@ function clearChatMessages()
g_ChatMessages.length = 0;
Engine.GetGUIObjectByName("chatText").caption = "";
try {
try
{
for (let timer of g_ChatTimers)
clearTimeout(timer);
g_ChatTimers.length = 0;
} catch (e) {
}
catch (e) {}
}
/**

View file

@ -1017,7 +1017,16 @@ function updateGameList()
Math.round(playerRatings.reduce((sum, current) => sum + current) / playerRatings.length) :
g_DefaultLobbyRating;
if (!hasSameMods(JSON.parse(game.mods), Engine.GetEngineInfo().mods))
try
{
game.mods = JSON.parse(game.mods);
}
catch (e)
{
game.mods = [];
}
if (!hasSameMods(game.mods, Engine.GetEngineInfo().mods))
game.state = "incompatible";
return game;
@ -1178,7 +1187,7 @@ function joinButton()
messageBox(
400, 200,
translate("Your active mods do not match the mods of this game.") + "\n\n" +
comparedModsString(JSON.parse(game.mods), Engine.GetEngineInfo().mods) + "\n\n" +
comparedModsString(game.mods, Engine.GetEngineInfo().mods) + "\n\n" +
translate("Do you want to switch to the mod selection page?"),
translate("Incompatible mods"),
[translate("No"), translate("Yes")],