summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-07-04 19:31:09 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-07-04 19:31:09 +0100
commit8270f9299fd8d3dbf658200f7f43bede170bfe71 (patch)
tree4450f1a9c37e3638c0a9b055768fb7891a5f839b /src
parent469eb6ec440bf695c3a41080da1728792771d457 (diff)
Improve robustness of json parsing and execution
Fixes #720
Diffstat (limited to 'src')
-rw-r--r--src/json_ui.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/json_ui.cc b/src/json_ui.cc
index c7829b1b..8ce6aff5 100644
--- a/src/json_ui.cc
+++ b/src/json_ui.cc
@@ -360,6 +360,9 @@ parse_json(StringView json) { return parse_json(json.begin(), json.end()); }
void JsonUI::eval_json(const Value& json)
{
+ if (not json.is_a<JsonObject>())
+ throw runtime_error("json request is not an object");
+
const JsonObject& object = json.as<JsonObject>();
auto json_it = object.find("jsonrpc");
if (json_it == object.end() or json_it->value.as<String>() != "2.0")
@@ -436,14 +439,8 @@ void JsonUI::parse_requests(EventMode mode)
{
write_stderr(format("error while handling requests '{}': '{}'",
m_requests, error.what()));
-
// try to salvage request by dropping its first line
- auto eol = find(m_requests, '\n');
- if (eol != m_requests.end())
- m_requests = String{eol+1, m_requests.end()};
- else
- m_requests = String{};
-
+ pos = std::min(m_requests.end(), find(m_requests, '\n')+1);
}
if (pos)
m_requests = String{pos, m_requests.end()};