GH-4227 Don't blindly trust mods.toml to be valid

This commit is contained in:
Janrupf 2021-11-06 22:42:10 +01:00
parent 2576a28f73
commit 0423464b88

View File

@ -107,8 +107,19 @@ std::shared_ptr<ModDetails> ReadMCModTOML(QByteArray contents)
// array defined by [[mods]] // array defined by [[mods]]
toml_array_t* tomlModsArr = toml_array_in(tomlData, "mods"); toml_array_t* tomlModsArr = toml_array_in(tomlData, "mods");
if(!tomlModsArr)
{
qWarning() << "Corrupted mods.toml? Couldn't find [[mods]] array!";
return nullptr;
}
// we only really care about the first element, since multiple mods in one file is not supported by us at the moment // we only really care about the first element, since multiple mods in one file is not supported by us at the moment
toml_table_t* tomlModsTable0 = toml_table_at(tomlModsArr, 0); toml_table_t* tomlModsTable0 = toml_table_at(tomlModsArr, 0);
if(!tomlModsTable0)
{
qWarning() << "Corrupted mods.toml? [[mods]] didn't have an element at index 0!";
return nullptr;
}
// mandatory properties - always in [[mods]] // mandatory properties - always in [[mods]]
toml_datum_t modIdDatum = toml_string_in(tomlModsTable0, "modId"); toml_datum_t modIdDatum = toml_string_in(tomlModsTable0, "modId");