[Libreoffice-commits] online.git: loleaflet/src loolwsd/ChildSession.cpp

Pranav Kant pranavk at collabora.co.uk
Fri Sep 23 10:46:27 UTC 2016


 loleaflet/src/layer/tile/TileLayer.js |    6 +++++-
 loolwsd/ChildSession.cpp              |    6 ++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

New commits:
commit 2579e1191c0597df42655eca7539c0a0ce9c3d0f
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Sep 23 15:38:50 2016 +0530

    loolwsd: Prevent passing a nullptr to std::string()
    
    Undefined behavior.
    
    Change-Id: I2ddcb0a5cba1d593791ced62783d02e732162d17

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index e0197ff..788a962 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -391,7 +391,11 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	_onCommandValuesMsg: function (textMsg) {
-		var obj = JSON.parse(textMsg.substring(textMsg.indexOf('{')));
+		var jsonIdx = textMsg.indexOf('{');
+		if (jsonIdx === -1) {
+			return;
+		}
+		var obj = JSON.parse(textMsg.substring(jsonIdx));
 		if (obj.commandName == '.uno:DocumentRepair') {
 			this._onDocumentRepair(obj);
 		}
diff --git a/loolwsd/ChildSession.cpp b/loolwsd/ChildSession.cpp
index a915e0a..094de82 100644
--- a/loolwsd/ChildSession.cpp
+++ b/loolwsd/ChildSession.cpp
@@ -409,14 +409,16 @@ bool ChildSession::getCommandValues(const char* /*buffer*/, int /*length*/, Stri
         const std::string json("{\"commandName\":\".uno:DocumentRepair\",\"Redo\":%s,\"Undo\":%s}");
         pValues = _loKitDocument->getCommandValues(".uno:Redo");
         pUndo = _loKitDocument->getCommandValues(".uno:Undo");
-        success = sendTextFrame("commandvalues: " + Poco::format(json, std::string(pValues), std::string(pUndo)));
+        success = sendTextFrame("commandvalues: " + Poco::format(json,
+                                                                 std::string(pValues == nullptr ? "" : pValues),
+                                                                 std::string(pUndo == nullptr ? "" : pUndo)));
         std::free(pValues);
         std::free(pUndo);
     }
     else
     {
         pValues = _loKitDocument->getCommandValues(command.c_str());
-        success = sendTextFrame("commandvalues: " + std::string(pValues));
+        success = sendTextFrame("commandvalues: " + std::string(pValues == nullptr ? "" : pValues));
         std::free(pValues);
     }
 


More information about the Libreoffice-commits mailing list