l10ntools/source/cfgmerge.cxx |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

New commits:
commit cb24017c84efdc91a73d91655664d9ae01a1d6d6
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Sun Nov 20 17:52:34 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Sun Nov 20 22:40:27 2022 +0100

    Clean up CfgParser::aStack
    
    This is apparently some very old, very poor XML parsing code full of
    questionable design decisions.  The silliness of pushing onto the 
opened-element
    stack also entities that don't have a closing tag (but which cannot easily 
be
    changed, see the added comment about CfgStack::GetAccessPath) caused 
consistent
    memory leaks when Executable_cfgex is executed during the build.  While 
those
    leaks are harmless, they might cause people to nevertheless try to clean 
them up
    in various ways (see the abandoned
    <https://gerrit.libreoffice.org/c/core/+/142718> "asan: fix leak in
    ExecuteAnalyzedToken/Push"), so just clean up those broken-by-design excess
    aStack elements.
    
    Change-Id: I849109906c6b102d9aa90300c2bada360c727d4d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143001
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx
index 1e43f3e99394..f07323ef7efd 100644
--- a/l10ntools/source/cfgmerge.cxx
+++ b/l10ntools/source/cfgmerge.cxx
@@ -134,6 +134,21 @@ CfgParser::CfgParser()
 
 CfgParser::~CfgParser()
 {
+    // CfgParser::ExecuteAnalyzedToken pushes onto aStack some XML entities 
(like XML and document
+    // type declarations) that don't have corresponding closing tags, so will 
never be popped off
+    // aStack again.  But not pushing them onto aStack in the first place 
would change the
+    // identifiers computed in CfgStack::GetAccessPath, which could make the 
existing translation
+    // mechanisms fail.  So, for simplicity, and short of more thorough input 
error checking, take
+    // into account here all the patterns of such declarations encountered 
during a build and during
+    // `make translations` (some inputs start with no such declarations at 
all, some inputs start
+    // with an XML declaration, and some inputs start with an XML declaration 
followed by a document
+    // type declaration) and pop any corresponding remaining excess elements 
off aStack:
+    if (aStack.size() == 2 && aStack.GetStackData()->GetTagType() == 
"!DOCTYPE") {
+        aStack.Pop();
+    }
+    if (aStack.size() == 1 && aStack.GetStackData()->GetTagType() == "?xml") {
+        aStack.Pop();
+    }
 }
 
 bool CfgParser::IsTokenClosed(std::string_view rToken)

Reply via email to