include/xmloff/xmlictxt.hxx     |    6 ++++--
 sw/source/filter/xml/xmlimp.cxx |    2 +-
 xmloff/source/core/xmlictxt.cxx |    3 +++
 xmloff/source/core/xmlimp.cxx   |    4 ++--
 4 files changed, 10 insertions(+), 5 deletions(-)

New commits:
commit 813118bfbb453f812be9e1a30f84908b4e0bfb51
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Dec 20 14:34:56 2019 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Dec 20 19:26:18 2019 +0100

    add checks to optional fields in SvXMLImportContext
    
    so when I convert ImportContext to FastParser APIs I don't accidentally
    rely on data that is not there
    
    Change-Id: If4700c7902e11f98a57542943f6a198822689df8
    Reviewed-on: https://gerrit.libreoffice.org/85622
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/xmloff/xmlictxt.hxx b/include/xmloff/xmlictxt.hxx
index 8dc67dac0227..5ab75bce286e 100644
--- a/include/xmloff/xmlictxt.hxx
+++ b/include/xmloff/xmlictxt.hxx
@@ -51,6 +51,7 @@ class XMLOFF_DLLPUBLIC SvXMLImportContext : public 
css::xml::sax::XFastContextHa
     SvXMLImport&                       mrImport;
     sal_uInt16                         mnPrefix;
     OUString                           maLocalName;
+    bool                               mbPrefixAndLocalNameFilledIn;
     std::unique_ptr<SvXMLNamespaceMap> m_pRewindMap;
 
     SAL_DLLPRIVATE std::unique_ptr<SvXMLNamespaceMap> TakeRewindMap() { return 
std::move(m_pRewindMap); }
@@ -63,8 +64,9 @@ protected:
 
 public:
 
-    sal_uInt16 GetPrefix() const { return mnPrefix; }
-    const OUString& GetLocalName() const { return maLocalName; }
+    bool IsPrefixFilledIn() const { return mnPrefix != 0; }
+    sal_uInt16 GetPrefix() const { assert(mbPrefixAndLocalNameFilledIn && 
"those fields not filled, probably fast-parser context"); return mnPrefix; }
+    const OUString& GetLocalName() const { assert(mbPrefixAndLocalNameFilledIn 
&& "those fields not filled, probably fast-parser context"); return 
maLocalName; }
 
     /** A contexts constructor does anything that is required if an element
      * starts. Namespace processing has been done already.
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index ebbd220e65a1..6b9a18327714 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -244,7 +244,7 @@ SvXMLImportContextRef 
SwXMLDocContext_Impl::CreateChildContext(
         break;
     case XML_TOK_DOC_AUTOSTYLES:
         // don't use the autostyles from the styles-document for the progress
-        if ( ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
+        if ( !IsPrefixFilledIn() || ! IsXMLToken( GetLocalName(), 
XML_DOCUMENT_STYLES ) )
             GetSwImport().GetProgressBarHelper()->Increment
                 ( PROGRESS_BAR_STEP );
         pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index 092b1845c18c..b05a76b39969 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -32,13 +32,16 @@ SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp, 
sal_uInt16 nPrfx,
     , mrImport(rImp)
     , mnPrefix(nPrfx)
     , maLocalName(rLName)
+    , mbPrefixAndLocalNameFilledIn(true)
 {
+    assert(!rLName.isEmpty());
 }
 
 SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp )
     : m_nRefCount(0)
     , mrImport(rImp)
     , mnPrefix(0)
+    , mbPrefixAndLocalNameFilledIn(false)
 {
 }
 
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 9c1f806a999c..578bef43a82c 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -729,7 +729,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& 
rName,
     if(!maContexts.empty())
     {
         xContext = maContexts.top()->CreateChildContext(nPrefix, aLocalName, 
xAttrList);
-        SAL_WARN_IF( !xContext.is() || (xContext->GetPrefix() != nPrefix), 
"xmloff.core",
+        SAL_WARN_IF( xContext.is() && xContext->IsPrefixFilledIn() && 
(xContext->GetPrefix() != nPrefix), "xmloff.core",
                 "SvXMLImport::startElement: created context has wrong prefix" 
);
     }
     else
@@ -782,7 +782,7 @@ rName
 
 #ifdef DBG_UTIL
         // Non product only: check if endElement call matches startELement 
call.
-        if (!xContext->GetLocalName().isEmpty()) // prefix+localname are only 
valid in the non-FastParser case
+        if (xContext->IsPrefixFilledIn()) // prefix+localname are only valid 
in the non-FastParser case
         {
             OUString aLocalName;
             sal_uInt16 nPrefix =
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to