summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2022-01-06 17:26:15 +0100
committerAndras Timar <andras.timar@collabora.com>2022-01-25 22:06:24 +0100
commit9fa9005786ff65cf7d6d9812a45274f0efdb9f62 (patch)
treed310b10e9b3dbe001e60e98ff8cd64ddc90960be
parentcalc: fix moving the tabs break comments on it (diff)
downloadonline-9fa9005786ff65cf7d6d9812a45274f0efdb9f62.tar.gz
online-9fa9005786ff65cf7d6d9812a45274f0efdb9f62.zip
Handle JSON exception when parsing commands fixes #3916
Signed-off-by: Szymon Kłos <szymon.klos@collabora.com> Change-Id: I9bd78ded46d1b5cd4816a106b138583e540f0712
-rw-r--r--wsd/ClientSession.cpp105
1 files changed, 63 insertions, 42 deletions
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index fe1a70f4af..0e505f42e2 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1447,29 +1447,36 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
const size_t index = stringMsg.find_first_of('{');
if (index != std::string::npos)
{
- const std::string stringJSON = stringMsg.substr(index);
- Poco::JSON::Parser parser;
- const Poco::Dynamic::Var parsedJSON = parser.parse(stringJSON);
- const auto& object = parsedJSON.extract<Poco::JSON::Object::Ptr>();
- if (object->get("commandName").toString() == ".uno:Save")
+ try
{
- const bool success = object->get("success").toString() == "true";
- std::string result;
- if (object->has("result"))
+ const std::string stringJSON = stringMsg.substr(index);
+ Poco::JSON::Parser parser;
+ const Poco::Dynamic::Var parsedJSON = parser.parse(stringJSON);
+ const auto& object = parsedJSON.extract<Poco::JSON::Object::Ptr>();
+ if (object->get("commandName").toString() == ".uno:Save")
{
- const Poco::Dynamic::Var parsedResultJSON = object->get("result");
- const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>();
- if (resultObj->get("type").toString() == "string")
- result = resultObj->get("value").toString();
- }
+ const bool success = object->get("success").toString() == "true";
+ std::string result;
+ if (object->has("result"))
+ {
+ const Poco::Dynamic::Var parsedResultJSON = object->get("result");
+ const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>();
+ if (resultObj->get("type").toString() == "string")
+ result = resultObj->get("value").toString();
+ }
- // Save to Storage and log result.
- docBroker->handleSaveResponse(getId(), success, result);
+ // Save to Storage and log result.
+ docBroker->handleSaveResponse(getId(), success, result);
- if (!isCloseFrame())
- forwardToClient(payload);
+ if (!isCloseFrame())
+ forwardToClient(payload);
- return true;
+ return true;
+ }
+ }
+ catch (const std::exception& exception)
+ {
+ LOG_ERR("unocommandresult parsing failure: " << exception.what());
}
}
else
@@ -1831,16 +1838,23 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
const size_t index = stringMsg.find_first_of('{');
if (index != std::string::npos)
{
- const std::string stringJSON = stringMsg.substr(index);
- Poco::JSON::Parser parser;
- const Poco::Dynamic::Var result = parser.parse(stringJSON);
- const auto& object = result.extract<Poco::JSON::Object::Ptr>();
- const std::string commandName = object->has("commandName") ? object->get("commandName").toString() : "";
- if (commandName == ".uno:CharFontName" ||
- commandName == ".uno:StyleApply")
+ try
+ {
+ const std::string stringJSON = stringMsg.substr(index);
+ Poco::JSON::Parser parser;
+ const Poco::Dynamic::Var result = parser.parse(stringJSON);
+ const auto& object = result.extract<Poco::JSON::Object::Ptr>();
+ const std::string commandName = object->has("commandName") ? object->get("commandName").toString() : "";
+ if (commandName == ".uno:CharFontName" ||
+ commandName == ".uno:StyleApply")
+ {
+ // other commands should not be cached
+ docBroker->tileCache().saveTextStream(TileCache::StreamType::CmdValues, stringMsg, commandName);
+ }
+ }
+ catch (const std::exception& exception)
{
- // other commands should not be cached
- docBroker->tileCache().saveTextStream(TileCache::StreamType::CmdValues, stringMsg, commandName);
+ LOG_ERR("commandvalues parsing failure: " << exception.what());
}
}
}
@@ -1861,26 +1875,33 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
const size_t index = firstLine.find_first_of('{');
const std::string stringJSON = firstLine.substr(index);
Poco::JSON::Parser parser;
- const Poco::Dynamic::Var result = parser.parse(stringJSON);
- const auto& object = result.extract<Poco::JSON::Object::Ptr>();
- const std::string rectangle = object->get("rectangle").toString();
- StringVector rectangleTokens(Util::tokenize(rectangle, ','));
- int x = 0, y = 0, w = 0, h = 0;
- if (rectangleTokens.size() > 2 &&
- stringToInteger(rectangleTokens[0], x) &&
- stringToInteger(rectangleTokens[1], y))
+ try
{
- if (rectangleTokens.size() > 3)
+ const Poco::Dynamic::Var result = parser.parse(stringJSON);
+ const auto& object = result.extract<Poco::JSON::Object::Ptr>();
+ const std::string rectangle = object->get("rectangle").toString();
+ StringVector rectangleTokens(Util::tokenize(rectangle, ','));
+ int x = 0, y = 0, w = 0, h = 0;
+ if (rectangleTokens.size() > 2 &&
+ stringToInteger(rectangleTokens[0], x) &&
+ stringToInteger(rectangleTokens[1], y))
{
- stringToInteger(rectangleTokens[2], w);
- stringToInteger(rectangleTokens[3], h);
- }
+ if (rectangleTokens.size() > 3)
+ {
+ stringToInteger(rectangleTokens[2], w);
+ stringToInteger(rectangleTokens[3], h);
+ }
- docBroker->invalidateCursor(x, y, w, h);
+ docBroker->invalidateCursor(x, y, w, h);
+ }
+ else
+ {
+ LOG_ERR("Unable to parse " << firstLine);
+ }
}
- else
+ catch (const std::exception& exception)
{
- LOG_ERR("Unable to parse " << firstLine);
+ LOG_ERR("invalidatecursor parsing failure: " << exception.what());
}
}
else if (tokens[0] == "renderfont:")