Skip to content

Commit

Permalink
fix: Do not crash on unknown MAD manifesto format (R2Northstar#749)
Browse files Browse the repository at this point in the history
Verify JSON has attributes before trying to access them
  • Loading branch information
Alystrasz authored and wolf109909 committed Jul 30, 2024
1 parent e01944f commit 1df1de1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions primedev/mods/autodownload/moddownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ void ModDownloader::FetchModsListFromAPI()
verifiedModsJson.Parse(readBuffer);
for (auto i = verifiedModsJson.MemberBegin(); i != verifiedModsJson.MemberEnd(); ++i)
{
// Format testing
if (!i->value.HasMember("DependencyPrefix") || !i->value.HasMember("Versions"))
{
spdlog::warn("Verified mods manifesto format is unrecognized, skipping loading.");
return;
}

std::string name = i->name.GetString();
std::string dependency = i->value["DependencyPrefix"].GetString();

Expand All @@ -104,6 +111,13 @@ void ModDownloader::FetchModsListFromAPI()
for (auto& attribute : versions.GetArray())
{
assert(attribute.IsObject());
// Format testing
if (!attribute.HasMember("Version") || !attribute.HasMember("Checksum"))
{
spdlog::warn("Verified mods manifesto format is unrecognized, skipping loading.");
return;
}

std::string version = attribute["Version"].GetString();
std::string checksum = attribute["Checksum"].GetString();
modVersions.insert({version, {.checksum = checksum}});
Expand Down

0 comments on commit 1df1de1

Please sign in to comment.