Validate json root is an object before trying to retrieve members from it.

This commit is contained in:
O-Robotic 2023-09-07 20:15:22 +01:00
parent 5c3b7d1b56
commit 51dd17ad2a
2 changed files with 14 additions and 1 deletions

View File

@ -40,6 +40,12 @@ void CBanSystem::LoadList(void)
return;
}
if (!document.IsObject())
{
Warning(eDLL_T::SERVER, "%s: JSON root was not an object\n", __FUNCTION__);
return;
}
uint64_t nTotalBans = 0;
if (document.HasMember("totalBans") && document["totalBans"].IsUint64())
{

View File

@ -337,6 +337,12 @@ bool CPylon::SendRequest(const char* endpoint, const rapidjson::Document& reques
return false;
}
if (!responseJson.IsObject())
{
Warning(eDLL_T::SERVER, "%s: JSON root was not an object\n", __FUNCTION__);
return false;
}
if (pylon_showdebuginfo->GetBool())
{
LogBody(responseJson);
@ -429,7 +435,8 @@ bool CPylon::QueryServer(const char* endpoint, const char* request,
void CPylon::ExtractError(const rapidjson::Document& resultJson, string& outMessage,
CURLINFO status, const char* errorText) const
{
if (resultJson.HasMember("error") &&
if (resultJson.IsObject() && resultJson.HasMember("error") &&
resultJson["error"].IsString())
{
outMessage = resultJson["error"].GetString();