aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-27 09:46:29 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-27 09:46:29 +0200
commitb07cca0bb59300fe193015f1a8361448af72d05b (patch)
treee89f0b12e84a2a1cfa2faed918e7aea83f37e95d
parent4f89aee77ede589002ab75490fa1ab2a3ca3fe84 (diff)
Validate json type after parsing
-rw-r--r--src/VideoPlayer.cpp2
-rw-r--r--src/plugins/Fourchan.cpp9
-rw-r--r--src/plugins/Mangadex.cpp6
-rw-r--r--src/plugins/Matrix.cpp9
4 files changed, 22 insertions, 4 deletions
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index 0ad4152..ac93ecc 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -254,7 +254,7 @@ namespace QuickMedia {
if(buffer[i] != '\n')
continue;
- if(json_reader->parse(buffer + start, buffer + i, &json_root, &json_errors)) {
+ if(json_reader->parse(buffer + start, buffer + i, &json_root, &json_errors) && json_root.isObject()) {
const Json::Value &event = json_root["event"];
const Json::Value &request_id_json = json_root["request_id"];
if(event.isString()) {
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index a70070e..5da2961 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -93,6 +93,9 @@ namespace QuickMedia {
return PluginResult::ERR;
}
+ if(!json_root.isObject())
+ return PluginResult::ERR;
+
const Json::Value &boards = json_root["boards"];
if(boards.isArray()) {
for(const Json::Value &board : boards) {
@@ -412,6 +415,9 @@ namespace QuickMedia {
return PluginResult::ERR;
}
+ if(!json_root.isObject())
+ return PluginResult::ERR;
+
std::unordered_map<int64_t, size_t> comment_by_postno;
const Json::Value &posts = json_root["posts"];
@@ -632,6 +638,9 @@ namespace QuickMedia {
return PluginResult::ERR;
}
+ if(!json_root.isObject())
+ return PluginResult::ERR;
+
const Json::Value &status_json = json_root["status"];
if(!status_json.isNumeric())
return PluginResult::ERR;
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp
index 6a8f8a7..fcbd23e 100644
--- a/src/plugins/Mangadex.cpp
+++ b/src/plugins/Mangadex.cpp
@@ -52,6 +52,9 @@ namespace QuickMedia {
return SearchResult::ERR;
}
+ if(!json_root.isObject())
+ return SearchResult::ERR;
+
Json::Value &status_json = json_root["status"];
if(!status_json.isString() || status_json.asString() != "OK")
return SearchResult::ERR;
@@ -287,6 +290,9 @@ namespace QuickMedia {
return ImageResult::ERR;
}
+ if(!json_root.isObject())
+ return ImageResult::ERR;
+
Json::Value &status_json = json_root["status"];
if(!status_json.isString() || status_json.asString() != "OK")
return ImageResult::ERR;
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 71e451d..3ce6ffd 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -572,7 +572,7 @@ namespace QuickMedia {
{ "-H", "Authorization: Bearer " + access_token }
};
- std::string filter = url_param_encode(Json::writeString(builder, request_data));
+ std::string filter = url_param_encode(Json::writeString(builder, std::move(request_data)));
char url[512];
snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/messages?from=%s&limit=20&dir=b&filter=%s", homeserver.c_str(), room_id.c_str(), from.c_str(), filter.c_str());
@@ -704,7 +704,7 @@ namespace QuickMedia {
{ "-X", "PUT" },
{ "-H", "content-type: application/json" },
{ "-H", "Authorization: Bearer " + access_token },
- { "--data-binary", Json::writeString(builder, request_data) }
+ { "--data-binary", Json::writeString(builder, std::move(request_data)) }
};
char request_url[512];
@@ -874,7 +874,7 @@ namespace QuickMedia {
std::vector<CommandArg> additional_args = {
{ "-X", "POST" },
{ "-H", "content-type: application/json" },
- { "--data-binary", Json::writeString(builder, request_data) }
+ { "--data-binary", Json::writeString(builder, std::move(request_data)) }
};
std::string server_response;
@@ -956,6 +956,9 @@ namespace QuickMedia {
return PluginResult::ERR;
}
+ if(!json_root.isObject())
+ return PluginResult::ERR;
+
const Json::Value &user_id_json = json_root["user_id"];
if(!user_id_json.isString()) {
fprintf(stderr, "Failed to parse matrix cached session response\n");