loolwsd/LOOLProtocol.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
New commits: commit 2bb2e2aec1291468e3e03cff963fffbaad4b0241 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sat Jan 23 17:33:19 2016 -0500 loolwsd: protect against empty messages Change-Id: Ic60c1abf85268c9ad629bc1f981e53688fc6267a Reviewed-on: https://gerrit.libreoffice.org/21753 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/LOOLProtocol.cpp b/loolwsd/LOOLProtocol.cpp index 20c5d8e..993ef61 100644 --- a/loolwsd/LOOLProtocol.cpp +++ b/loolwsd/LOOLProtocol.cpp @@ -152,6 +152,9 @@ namespace LOOLProtocol std::string getFirstLine(const char *message, int length) { + if (message == nullptr || length <= 0) + return ""; + const char *endOfLine = static_cast<const char *>(std::memchr(message, '\n', length)); if (endOfLine == nullptr) return std::string(message, length); @@ -161,8 +164,12 @@ namespace LOOLProtocol std::string getAbbreviatedMessage(const char *message, int length) { - std::string result = "'" + getFirstLine(message, length) + "'"; - if (result.size() < static_cast<std::string::size_type>(length)) + if (message == nullptr || length <= 0) + return ""; + + const auto firstLine = getFirstLine(message, length); + std::string result = "'" + firstLine + "'"; + if (firstLine.size() < static_cast<std::string::size_type>(length)) result += "..."; return result; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits