kit/ChildSession.cpp | 16 +++++++++------- test/httpwstest.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-)
New commits: commit 6cd1d511bef99c2334b415daa76dfc89a3728faf Author: Ashod Nakashian <[email protected]> Date: Thu Feb 9 21:15:25 2017 -0500 wsd: avoid segfault when handling invalid paste command The payload of paste can't have length 0. Now we silently skip such cases, although perhaps we should be more strict and disconnect the offending client. Change-Id: Iaa2e7373277f9e7d85209aec56a2f8ee0ef7e801 Reviewed-on: https://gerrit.libreoffice.org/34112 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 9035fed..8c6942e 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -648,8 +648,8 @@ bool ChildSession::getTextSelection(const char* /*buffer*/, int /*length*/, cons bool ChildSession::paste(const char* buffer, int length, const std::vector<std::string>& tokens) { std::string mimeType; - - if (tokens.size() < 2 || !getTokenString(tokens[1], "mimetype", mimeType)) + if (tokens.size() < 2 || !getTokenString(tokens[1], "mimetype", mimeType) || + mimeType.empty()) { sendTextFrame("error: cmd=paste kind=syntax"); return false; @@ -657,13 +657,15 @@ bool ChildSession::paste(const char* buffer, int length, const std::vector<std:: const std::string firstLine = getFirstLine(buffer, length); const char* data = buffer + firstLine.size() + 1; - const size_t size = length - firstLine.size() - 1; - - std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex()); + const int size = length - firstLine.size() - 1; + if (size > 0) + { + std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex()); - getLOKitDocument()->setView(_viewId); + getLOKitDocument()->setView(_viewId); - getLOKitDocument()->paste(mimeType.c_str(), data, size); + getLOKitDocument()->paste(mimeType.c_str(), data, size); + } return true; } diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp index 09803ef..c1044ca 100644 --- a/test/httpwstest.cpp +++ b/test/httpwstest.cpp @@ -72,6 +72,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testReloadWhileDisconnecting); CPPUNIT_TEST(testExcelLoad); CPPUNIT_TEST(testPaste); + CPPUNIT_TEST(testPasteBlank); CPPUNIT_TEST(testLargePaste); CPPUNIT_TEST(testRenderingOptions); CPPUNIT_TEST(testPasswordProtectedDocumentWithoutPassword); @@ -124,6 +125,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testReloadWhileDisconnecting(); void testExcelLoad(); void testPaste(); + void testPasteBlank(); void testLargePaste(); void testRenderingOptions(); void testPasswordProtectedDocumentWithoutPassword(); @@ -772,6 +774,32 @@ void HTTPWSTest::testPaste() } } +void HTTPWSTest::testPasteBlank() +{ + const auto testname = "pasteBlank "; + try + { + // Load a document and make it empty, then paste nothing into it. + auto socket = loadDocAndGetSocket("hello.odt", _uri, testname); + + sendTextFrame(socket, "uno .uno:SelectAll", testname); + sendTextFrame(socket, "uno .uno:Delete", testname); + + // Paste nothing into it. + sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8", testname); + + // Check if the document contains the pasted text. + sendTextFrame(socket, "uno .uno:SelectAll", testname); + sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8", testname); + const auto selection = assertResponseString(socket, "textselectioncontent:", testname); + CPPUNIT_ASSERT_EQUAL(std::string("textselectioncontent: "), selection); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } +} + void HTTPWSTest::testLargePaste() { const auto testname = "LargePaste "; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
