[Libreoffice-commits] core.git: sw/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue Sep 21 13:18:05 UTC 2021
sw/source/filter/ww8/docxattributeoutput.cxx | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
New commits:
commit 1d4f198f176cfb5816b76ad67b6c0df39419f0cb
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Sep 21 13:17:11 2021 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Sep 21 15:17:31 2021 +0200
Fix splitting of "permission-for-group/-user:" strings
...that had been introduced in f5c266695a4a88da7db971a21915e2bbf758d48e
"tdf#66398 Parse and output permissions for DOCX using bookmarks":
For one, in DocxAttributeOutput::DoWritePermissionTagStart permissionIdAndName
was left empty in the permission-for-user case. This had already been addressed
for DocxAttributeOutput::DoWritePermissionTagEnd in
7f0b7410e84a222d8fbee7c4fadd3b40028a068d "permissionIdAndName is empty in
permission-for-user case". But from the calling code it looks like in both
functions that permission will always start with either "permission-for-group:"
or "permission-for-user:", so assert that rather than silently doing nothing if
the assumption is wrong.
For another, in both functions the code didn't take any precaution if
permissionIdAndName didn't contain a colon (which would cause undefined behavior
when OUString::copy is called with a negative count argument). Again, from the
calling code assume that permissionIdAndName will always contain a colon, and
assert that.
Change-Id: Ia7432413c138d47efbe8aec76f14c561ac241fb3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122387
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index c2aa3880ece0..5da71ff6f820 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1794,6 +1794,7 @@ void DocxAttributeOutput::DoWritePermissionTagStart(const OUString & permission)
if (permission.startsWith("permission-for-group:", &permissionIdAndName))
{
const sal_Int32 sparatorIndex = permissionIdAndName.indexOf(':');
+ assert(sparatorIndex != -1);
const OUString permissionId = permissionIdAndName.copy(0, sparatorIndex);
const OUString permissionName = permissionIdAndName.copy(sparatorIndex + 1);
@@ -1801,9 +1802,12 @@ void DocxAttributeOutput::DoWritePermissionTagStart(const OUString & permission)
FSNS(XML_w, XML_id), BookmarkToWord(permissionId),
FSNS(XML_w, XML_edGrp), BookmarkToWord(permissionName));
}
- else // if (permission.startsWith("permission-for-user:", &permissionIdAndName))
+ else
{
+ auto const ok = permission.startsWith("permission-for-user:", &permissionIdAndName);
+ assert(ok); (void)ok;
const sal_Int32 sparatorIndex = permissionIdAndName.indexOf(':');
+ assert(sparatorIndex != -1);
const OUString permissionId = permissionIdAndName.copy(0, sparatorIndex);
const OUString permissionName = permissionIdAndName.copy(sparatorIndex + 1);
@@ -1825,15 +1829,16 @@ void DocxAttributeOutput::DoWritePermissionTagEnd(const OUString & permission)
{
OUString permissionIdAndName;
- if (permission.startsWith("permission-for-group:", &permissionIdAndName) ||
- permission.startsWith("permission-for-user:", &permissionIdAndName))
- {
- const sal_Int32 sparatorIndex = permissionIdAndName.indexOf(':');
- const OUString permissionId = permissionIdAndName.copy(0, sparatorIndex);
+ auto const ok = permission.startsWith("permission-for-group:", &permissionIdAndName) ||
+ permission.startsWith("permission-for-user:", &permissionIdAndName);
+ assert(ok); (void)ok;
- m_pSerializer->singleElementNS(XML_w, XML_permEnd,
- FSNS(XML_w, XML_id), BookmarkToWord(permissionId));
- }
+ const sal_Int32 sparatorIndex = permissionIdAndName.indexOf(':');
+ assert(sparatorIndex != -1);
+ const OUString permissionId = permissionIdAndName.copy(0, sparatorIndex);
+
+ m_pSerializer->singleElementNS(XML_w, XML_permEnd,
+ FSNS(XML_w, XML_id), BookmarkToWord(permissionId));
}
/// Write the start permissions
More information about the Libreoffice-commits
mailing list