From 364c74df930633bf897cacf391f6dc24dbc183b8 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 26 Jul 2016 14:13:38 +0600 Subject: CLOUD: Update DropboxStorage JSON checks added. --- backends/cloud/dropbox/dropboxstorage.cpp | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 789f6b497c..d12070316b 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -92,25 +92,34 @@ void DropboxStorage::getAccessToken(Common::String code) { void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) { Common::JSONValue *json = (Common::JSONValue *)response.value; - if (json) { - Common::JSONObject result = json->asObject(); - if (!result.contains("access_token") || !result.contains("uid")) { - warning("DropboxStorage: bad response, no token/uid passed"); - debug(9, "%s", json->stringify(true).c_str()); - CloudMan.removeStorage(this); - } else { - _token = result.getVal("access_token")->asString(); - _uid = result.getVal("uid")->asString(); - ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); - CloudMan.replaceStorage(this, kStorageDropboxId); - ConfMan.flushToDisk(); - } + if (json == nullptr) { + debug(9, "DropboxStorage::codeFlowComplete: got NULL instead of JSON!"); + CloudMan.removeStorage(this); + return; + } + if (!json->isObject()) { + debug(9, "DropboxStorage::codeFlowComplete: Passed JSON is not an object!"); + CloudMan.removeStorage(this); delete json; - } else { - debug(9, "DropboxStorage::codeFlowComplete: got NULL instead of JSON!"); + return; + } + + Common::JSONObject result = json->asObject(); + if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "DropboxStorage::codeFlowComplete") || + !Networking::CurlJsonRequest::jsonContainsString(result, "uid", "DropboxStorage::codeFlowComplete")) { + warning("DropboxStorage: bad response, no token/uid passed"); + debug(9, "%s", json->stringify(true).c_str()); CloudMan.removeStorage(this); + } else { + _token = result.getVal("access_token")->asString(); + _uid = result.getVal("uid")->asString(); + ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); + CloudMan.replaceStorage(this, kStorageDropboxId); + ConfMan.flushToDisk(); } + + delete json; } void DropboxStorage::codeFlowFailed(Networking::ErrorResponse error) { -- cgit v1.2.3