cid#318862 Dereference after null check

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Idf2a678a56531b7e3c3a51f6e86582bb9ac69dc7
This commit is contained in:
Caolán McNamara 2023-10-17 11:05:15 +01:00 committed by Miklos Vajna
parent 93b5bdfd79
commit f86d894eb1

View file

@ -2227,14 +2227,18 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
else if (tokens.equals(0, "extractedlinktargets:")) else if (tokens.equals(0, "extractedlinktargets:"))
{ {
LOG_TRC("Sending extracted link targets response."); LOG_TRC("Sending extracted link targets response.");
if (!_saveAsSocket)
LOG_ERR("Error in extractedlinktargets: not in isConvertTo mode");
else
{
const std::string stringJSON = payload->jsonString();
const std::string stringJSON = payload->jsonString(); http::Response httpResponse(http::StatusCode::OK);
httpResponse.set("Last-Modified", Util::getHttpTimeNow());
http::Response httpResponse(http::StatusCode::OK); httpResponse.set("X-Content-Type-Options", "nosniff");
httpResponse.set("Last-Modified", Util::getHttpTimeNow()); httpResponse.setBody(stringJSON, "application/json");
httpResponse.set("X-Content-Type-Options", "nosniff"); _saveAsSocket->sendAndShutdown(httpResponse);
httpResponse.setBody(stringJSON, "application/json"); }
_saveAsSocket->sendAndShutdown(httpResponse);
// Now terminate. // Now terminate.
docBroker->closeDocument("extractedlinktargets"); docBroker->closeDocument("extractedlinktargets");
@ -2243,28 +2247,33 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
else if (tokens.equals(0, "sendthumbnail:")) else if (tokens.equals(0, "sendthumbnail:"))
{ {
LOG_TRC("Sending get-thumbnail response."); LOG_TRC("Sending get-thumbnail response.");
bool error = false; if (!_saveAsSocket)
LOG_ERR("Error in sendthumbnail: not in isConvertTo mode");
if (firstLine.find("error") != std::string::npos) else
error = true;
if (!error)
{ {
int firstLineSize = firstLine.size() + 1; bool error = false;
std::string thumbnail(payload->data().data() + firstLineSize, payload->data().size() - firstLineSize);
http::Response httpResponse(http::StatusCode::OK); if (firstLine.find("error") != std::string::npos)
httpResponse.set("Last-Modified", Util::getHttpTimeNow()); error = true;
httpResponse.set("X-Content-Type-Options", "nosniff");
httpResponse.setBody(thumbnail, "image/png");
_saveAsSocket->sendAndShutdown(httpResponse);
}
if (error) if (!error)
{ {
http::Response httpResponse(http::StatusCode::InternalServerError); int firstLineSize = firstLine.size() + 1;
httpResponse.set("Content-Length", "0"); std::string thumbnail(payload->data().data() + firstLineSize, payload->data().size() - firstLineSize);
_saveAsSocket->sendAndShutdown(httpResponse);
http::Response httpResponse(http::StatusCode::OK);
httpResponse.set("Last-Modified", Util::getHttpTimeNow());
httpResponse.set("X-Content-Type-Options", "nosniff");
httpResponse.setBody(thumbnail, "image/png");
_saveAsSocket->sendAndShutdown(httpResponse);
}
if (error)
{
http::Response httpResponse(http::StatusCode::InternalServerError);
httpResponse.set("Content-Length", "0");
_saveAsSocket->sendAndShutdown(httpResponse);
}
} }
docBroker->closeDocument("thumbnailgenerated"); docBroker->closeDocument("thumbnailgenerated");