From f86d894eb176c8e2bbe54c4af2a6909da8a8de32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 17 Oct 2023 11:05:15 +0100 Subject: [PATCH] cid#318862 Dereference after null check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Caolán McNamara Change-Id: Idf2a678a56531b7e3c3a51f6e86582bb9ac69dc7 --- wsd/ClientSession.cpp | 61 +++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 38ea9fe98..d20f0ab0c 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -2227,14 +2227,18 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr& pay else if (tokens.equals(0, "extractedlinktargets:")) { 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()); - httpResponse.set("X-Content-Type-Options", "nosniff"); - httpResponse.setBody(stringJSON, "application/json"); - _saveAsSocket->sendAndShutdown(httpResponse); + http::Response httpResponse(http::StatusCode::OK); + httpResponse.set("Last-Modified", Util::getHttpTimeNow()); + httpResponse.set("X-Content-Type-Options", "nosniff"); + httpResponse.setBody(stringJSON, "application/json"); + _saveAsSocket->sendAndShutdown(httpResponse); + } // Now terminate. docBroker->closeDocument("extractedlinktargets"); @@ -2243,28 +2247,33 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr& pay else if (tokens.equals(0, "sendthumbnail:")) { LOG_TRC("Sending get-thumbnail response."); - bool error = false; - - if (firstLine.find("error") != std::string::npos) - error = true; - - if (!error) + if (!_saveAsSocket) + LOG_ERR("Error in sendthumbnail: not in isConvertTo mode"); + else { - int firstLineSize = firstLine.size() + 1; - std::string thumbnail(payload->data().data() + firstLineSize, payload->data().size() - firstLineSize); + bool error = false; - 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 (firstLine.find("error") != std::string::npos) + error = true; - if (error) - { - http::Response httpResponse(http::StatusCode::InternalServerError); - httpResponse.set("Content-Length", "0"); - _saveAsSocket->sendAndShutdown(httpResponse); + if (!error) + { + int firstLineSize = firstLine.size() + 1; + std::string thumbnail(payload->data().data() + firstLineSize, payload->data().size() - firstLineSize); + + 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");