aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-22 20:02:36 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitf3959e140106334b33cf74832fc5b20d27407d0a (patch)
tree420bfa32f00fa24723176bd85dbc4b25cbda45df /backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp
parentf95073f0084b3fae3e2cbf14fd98135c37eabbdf (diff)
downloadscummvm-rg350-f3959e140106334b33cf74832fc5b20d27407d0a.tar.gz
scummvm-rg350-f3959e140106334b33cf74832fc5b20d27407d0a.tar.bz2
scummvm-rg350-f3959e140106334b33cf74832fc5b20d27407d0a.zip
CLOUD: Upload ListDirectory Requests
Lots of checks to avoid JSON-related segfaults added.
Diffstat (limited to 'backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp')
-rw-r--r--backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp b/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp
index 30a89a79d0..069d6fdfb1 100644
--- a/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp
+++ b/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp
@@ -104,20 +104,40 @@ void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonRespo
if (rq && rq->getNetworkReadStream())
error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode();
- if (!json) {
- error.failed = true;
+ if (json == nullptr) {
+ error.response = "Failed to parse JSON, null passed!";
finishError(error);
return;
}
+ if (!json->isObject()) {
+ error.response = "Passed JSON is not an object!";
+ finishError(error);
+ delete json;
+ return;
+ }
+
Common::JSONObject object = json->asObject();
- //TODO: check that ALL keys exist AND HAVE RIGHT TYPE to avoid segfaults
+ //check that ALL keys exist AND HAVE RIGHT TYPE to avoid segfaults
+ if (!Networking::CurlJsonRequest::jsonContainsArray(object, "value", "OneDriveListDirectoryRequest")) {
+ error.response = "\"value\" not found or that's not an array!";
+ finishError(error);
+ delete json;
+ return;
+ }
Common::JSONArray items = object.getVal("value")->asArray();
for (uint32 i = 0; i < items.size(); ++i) {
+ if (!Networking::CurlJsonRequest::jsonIsObject(items[i], "OneDriveListDirectoryRequest")) continue;
+
Common::JSONObject item = items[i]->asObject();
+ if (!Networking::CurlJsonRequest::jsonContainsAttribute(item, "folder", "OneDriveListDirectoryRequest", true)) continue;
+ if (!Networking::CurlJsonRequest::jsonContainsString(item, "name", "OneDriveListDirectoryRequest")) continue;
+ if (!Networking::CurlJsonRequest::jsonContainsIntegerNumber(item, "size", "OneDriveListDirectoryRequest")) continue;
+ if (!Networking::CurlJsonRequest::jsonContainsString(item, "lastModifiedDateTime", "OneDriveListDirectoryRequest")) continue;
+
Common::String path = _currentDirectory + item.getVal("name")->asString();
bool isDirectory = item.contains("folder");
uint32 size = item.getVal("size")->asIntegerNumber();
@@ -132,6 +152,13 @@ void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonRespo
bool hasMore = object.contains("@odata.nextLink");
if (hasMore) {
+ if (!Networking::CurlJsonRequest::jsonContainsString(object, "@odata.nextLink", "OneDriveListDirectoryRequest")) {
+ error.response = "\"@odata.nextLink\" is not a string!";
+ finishError(error);
+ delete json;
+ return;
+ }
+
makeRequest(object.getVal("@odata.nextLink")->asString());
} else {
listNextDirectory();