Fix crashes from badly formed json responses (LL's fault)

Adds LlsdFromJsonString, an exception-free wrapper for parsing json strings
LLSD objects that failed to parse through this will be the type Undefined.

Fixes crashes 36, 1G, 33, 21, and 3A.
This commit is contained in:
Liru Færs
2020-01-20 19:42:23 -05:00
parent 1fd6e91c68
commit deafc6814d
5 changed files with 61 additions and 14 deletions

View File

@@ -79,6 +79,17 @@ LLSD LlsdFromJson(const nlohmann::json &val)
return result;
}
LLSD LlsdFromJsonString(const std::string& str)
{
auto json = nlohmann::json::parse(str, nullptr, false);
if (json.is_discarded())
{
LL_WARNS() << "Cannot parse invalid json string:\n" << str << LL_ENDL;
return LLSD();
}
return LlsdFromJson(json);
}
//=========================================================================
nlohmann::json LlsdToJson(const LLSD &val)
{