1
0
mirror of https://github.com/Mauler125/r5sdk.git synced 2025-02-09 19:15:03 +01:00

Merge pull request from O-Robotic/json-validation

Validate json root is an object before trying to retrieve members
This commit is contained in:
Kawe Mazidjatari 2023-09-07 21:56:15 +02:00 committed by GitHub
commit 942e2c2a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions
r5dev/networksystem

@ -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())
{

@ -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();