summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2023-04-18 10:34:47 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-04-27 12:13:37 +0200
commit2fe581d916b76d613742c983731fb4a10b4ee95f (patch)
treeaa9b35ccd7e03100647d8dcee3143668a074b92f /tools
parentf62b1e17def7bc3881c7426229eabbaeb4cb5037 (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/+/150542 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Jenkins
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 e7a0f55fd6c2..3111cac2f816 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -236,7 +236,8 @@ void JsonWriter::put(std::string_view pPropName, std::string_view rPropVal)
++mPos;
// 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)
@@ -251,6 +252,9 @@ void JsonWriter::put(std::string_view 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'))