tools/source/misc/json_writer.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
New commits: commit 8790a9c408e3d8732993b228012eeb0c941ec2fb Author: Jaume Pujantell <jaume.pujant...@collabora.com> AuthorDate: Tue Apr 18 10:34:47 2023 +0200 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Tue Apr 18 13:33:23 2023 +0200 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.me...@collabora.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> 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'))