summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2023-04-18 10:34:47 +0200
committerMichael Meeks <michael.meeks@collabora.com>2023-04-18 13:33:23 +0200
commit8790a9c408e3d8732993b228012eeb0c941ec2fb (patch)
tree21b606806db39db6299c5f5fbbac0851e7ac4fbd /tools
parent5700349951fa4bba750836d6f4b0979b005e11c0 (diff)
fix bug in json_writer
Ruler stores null-terminated strings in fixed length char arrays, so when creating a JSON a string might end earlier that it's size sugsests. Change-Id: Icdcaf35f9ce54c24dcd36368dc49bb688a2a65ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150558 Tested-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/misc/json_writer.cxx6
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx
index 3d78f82e08e6..aea89a15d421 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -274,7 +274,8 @@ void JsonWriter::put(const char* pPropName, std::string_view rPropVal)
mPos += 4;
// copy and perform escaping
- for (size_t i = 0; i < rPropVal.size(); ++i)
+ bool bReachedEnd = false;
+ for (size_t i = 0; i < rPropVal.size() && !bReachedEnd; ++i)
{
char ch = rPropVal[i];
switch (ch)
@@ -289,6 +290,9 @@ void JsonWriter::put(const char* pPropName, std::string_view rPropVal)
case '\\':
writeEscapedSequence(ch, mPos);
break;
+ case 0:
+ bReachedEnd = true;
+ break;
case '\xE2': // Special processing of U+2028 and U+2029
if (i + 2 < rPropVal.size() && rPropVal[i + 1] == '\x80'
&& (rPropVal[i + 2] == '\xA8' || rPropVal[i + 2] == '\xA9'))