[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 2 commits - sax/source

Petr Mladek pmladek at kemper.freedesktop.org
Thu Jun 7 09:04:25 PDT 2012


 sax/source/expatwrap/sax_expat.cxx   |   72 +++++++++++++++++++++++------------
 sax/source/fastparser/fastparser.cxx |   36 +++++++++++++++++
 sax/source/fastparser/fastparser.hxx |    4 +
 3 files changed, 88 insertions(+), 24 deletions(-)

New commits:
commit 488c13b7b4e77f7ea9f89837d5b138316553362c
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri May 25 10:32:56 2012 +0200

    stop parsing on encountering internal entities in sax_expat.cxx
    
    The XML_UnparsedEntityDeclHandler is apparently deprecated anyway, so
    replace it with the newfangled XML_EntityDeclHandler.
    
    Change-Id: Ic6589c340cf9c4e52ee600b4ff5fe3808aa791bc
    
    Signed-off-by: Petr Mladek <pmladek at suse.cz>

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index df7dcfc..bf2473d 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -130,6 +130,16 @@ static void call_callbackCharacters( void *userData , const XML_Char *s , int nL
     pFastParser->callbackCharacters( s, nLen );
 }
 
+static void call_callbackEntityDecl(void *userData, const XML_Char *entityName,
+        int is_parameter_entity, const XML_Char *value, int value_length,
+        const XML_Char *base, const XML_Char *systemId,
+        const XML_Char *publicId, const XML_Char *notationName)
+{
+    FastSaxParser* pFastParser = reinterpret_cast<FastSaxParser*>(userData);
+    pFastParser->callbackEntityDecl(entityName, is_parameter_entity, value,
+            value_length, base, systemId, publicId, notationName);
+}
+
 static int call_callbackExternalEntityRef( XML_Parser parser,
         const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId )
 {
@@ -458,6 +468,7 @@ void FastSaxParser::parseStream( const InputSource& maStructSource) throw (SAXEx
     XML_SetUserData( entity.mpParser, this );
     XML_SetElementHandler( entity.mpParser, call_callbackStartElement, call_callbackEndElement );
     XML_SetCharacterDataHandler( entity.mpParser, call_callbackCharacters );
+    XML_SetEntityDeclHandler(entity.mpParser, call_callbackEntityDecl);
     XML_SetExternalEntityRefHandler( entity.mpParser, call_callbackExternalEntityRef );
 
     pushEntity( entity );
@@ -887,6 +898,31 @@ void FastSaxParser::callbackCharacters( const XML_Char* s, int nLen )
     }
 }
 
+void FastSaxParser::callbackEntityDecl(
+    const XML_Char * /*entityName*/,
+    int /*is_parameter_entity*/,
+    const XML_Char *value, int /*value_length*/,
+    const XML_Char * /*base*/,
+    const XML_Char * /*systemId*/,
+    const XML_Char * /*publicId*/,
+    const XML_Char * /*notationName*/)
+{
+    if (value) { // value != 0 means internal entity
+        OSL_TRACE("FastSaxParser: internal entity declaration, stopping");
+        XML_StopParser(getEntity().mpParser, XML_FALSE);
+        getEntity().maSavedException <<= SAXParseException(
+            ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+                    "FastSaxParser: internal entity declaration, stopping")),
+            static_cast<OWeakObject*>(this), Any(),
+            mxDocumentLocator->getPublicId(),
+            mxDocumentLocator->getSystemId(),
+            mxDocumentLocator->getLineNumber(),
+            mxDocumentLocator->getColumnNumber() );
+    } else {
+        OSL_TRACE("FastSaxParser: ignoring external entity declaration");
+    }
+}
+
 int FastSaxParser::callbackExternalEntityRef( XML_Parser parser,
         const XML_Char *context, const XML_Char * /*base*/, const XML_Char *systemId, const XML_Char *publicId )
 {
diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx
index 09a1d72..aac4e1d 100644
--- a/sax/source/fastparser/fastparser.hxx
+++ b/sax/source/fastparser/fastparser.hxx
@@ -127,6 +127,10 @@ public:
     void callbackEndElement( const XML_Char* name );
     void callbackCharacters( const XML_Char* s, int nLen );
     int callbackExternalEntityRef( XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId);
+    void callbackEntityDecl(const XML_Char *entityName, int is_parameter_entity,
+            const XML_Char *value, int value_length, const XML_Char *base,
+            const XML_Char *systemId, const XML_Char *publicId,
+            const XML_Char *notationName);
 
     inline void pushEntity( const Entity& rEntity ) { maEntities.push( rEntity ); }
     inline void popEntity()                         { maEntities.pop(); }
commit daa1f797d9dabbec57e613fd70edf045d3af683a
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri May 25 10:32:56 2012 +0200

    stop parsing on encountering internal entities in sax_expat.cxx
    
    The XML_UnparsedEntityDeclHandler is apparently deprecated anyway, so
    replace it with the newfangled XML_EntityDeclHandler.
    
    Change-Id: Ic5ed38ed6ded219c12020cef297b3867613325dd
    
    Signed-off-by: Petr Mladek <pmladek at suse.cz>

diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx
index 8587e28..cc305cd 100644
--- a/sax/source/expatwrap/sax_expat.cxx
+++ b/sax/source/expatwrap/sax_expat.cxx
@@ -270,12 +270,15 @@ public:
                                                 const XML_Char *sTarget ,
                                                 const XML_Char *sData );
 
-    void static callbackUnparsedEntityDecl( void *userData ,
-                                              const XML_Char *entityName,
-                                              const XML_Char *base,
-                                              const XML_Char *systemId,
-                                              const XML_Char *publicId,
-                                              const XML_Char *notationName);
+    void static callbackEntityDecl( void *userData ,
+                                    const XML_Char *entityName,
+                                    int is_parameter_entity,
+                                    const XML_Char *value,
+                                    int value_length,
+                                    const XML_Char *base,
+                                    const XML_Char *systemId,
+                                    const XML_Char *publicId,
+                                    const XML_Char *notationName);
 
     void static callbackNotationDecl(   void *userData,
                                         const XML_Char *notationName,
@@ -322,14 +325,19 @@ extern "C"
     {
         SaxExpatParser_Impl::callbackProcessingInstruction(userData,sTarget,sData );
     }
-    static void call_callbackUnparsedEntityDecl(void *userData ,
-                                                  const XML_Char *entityName,
-                                                const XML_Char *base,
-                                                const XML_Char *systemId,
-                                                const XML_Char *publicId,
-                                                const XML_Char *notationName)
+    static void call_callbackEntityDecl(void *userData ,
+                                        const XML_Char *entityName,
+                                        int is_parameter_entity,
+                                        const XML_Char *value,
+                                        int value_length,
+                                        const XML_Char *base,
+                                        const XML_Char *systemId,
+                                        const XML_Char *publicId,
+                                        const XML_Char *notationName)
     {
-        SaxExpatParser_Impl::callbackUnparsedEntityDecl(userData,entityName,base,systemId,publicId,notationName);
+        SaxExpatParser_Impl::callbackEntityDecl(userData, entityName,
+                is_parameter_entity, value, value_length,
+                base, systemId, publicId, notationName);
     }
     static void call_callbackNotationDecl(void *userData,
                                           const XML_Char *notationName,
@@ -494,8 +502,7 @@ void SaxExpatParser::parseStream(   const InputSource& structSource)
     XML_SetCharacterDataHandler( entity.pParser , call_callbackCharacters );
     XML_SetProcessingInstructionHandler(entity.pParser ,
                                         call_callbackProcessingInstruction );
-    XML_SetUnparsedEntityDeclHandler(   entity.pParser,
-                                        call_callbackUnparsedEntityDecl );
+    XML_SetEntityDeclHandler(entity.pParser, call_callbackEntityDecl);
     XML_SetNotationDeclHandler( entity.pParser, call_callbackNotationDecl );
     XML_SetExternalEntityRefHandler(    entity.pParser,
                                         call_callbackExternalEntityRef);
@@ -843,22 +850,39 @@ void SaxExpatParser_Impl::callbackProcessingInstruction(    void *pvThis,
 }
 
 
-void SaxExpatParser_Impl::callbackUnparsedEntityDecl(void *pvThis ,
+void SaxExpatParser_Impl::callbackEntityDecl(void *pvThis ,
                                                      const XML_Char *entityName,
+                                                     int /*is_parameter_entity*/,
+                                                     const XML_Char *value,
+                                                     int /*value_length*/,
                                                      const XML_Char * /*base*/,
                                                      const XML_Char *systemId,
                                                      const XML_Char *publicId,
                                                      const XML_Char *notationName)
 {
     SaxExpatParser_Impl *pImpl = ((SaxExpatParser_Impl*)pvThis);
-    if( pImpl->rDTDHandler.is() ) {
-        CALL_ELEMENT_HANDLER_AND_CARE_FOR_EXCEPTIONS(
-            pImpl ,
-            rDTDHandler->unparsedEntityDecl(
-                XML_CHAR_TO_OUSTRING( entityName ),
-                XML_CHAR_TO_OUSTRING( publicId ) ,
-                XML_CHAR_TO_OUSTRING( systemId ) ,
-                XML_CHAR_TO_OUSTRING( notationName ) ) );
+    if (value) { // value != 0 means internal entity
+        OSL_TRACE("SaxExpatParser: internal entity declaration, stopping");
+        XML_StopParser(pImpl->getEntity().pParser, XML_FALSE);
+        pImpl->exception = SAXParseException(
+            ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+                    "SaxExpatParser: internal entity declaration, stopping")),
+            0, Any(),
+            pImpl->rDocumentLocator->getPublicId(),
+            pImpl->rDocumentLocator->getSystemId(),
+            pImpl->rDocumentLocator->getLineNumber(),
+            pImpl->rDocumentLocator->getColumnNumber() );
+        pImpl->bExceptionWasThrown = sal_True;
+    } else {
+        if( pImpl->rDTDHandler.is() ) {
+            CALL_ELEMENT_HANDLER_AND_CARE_FOR_EXCEPTIONS(
+                pImpl ,
+                rDTDHandler->unparsedEntityDecl(
+                    XML_CHAR_TO_OUSTRING( entityName ),
+                    XML_CHAR_TO_OUSTRING( publicId ) ,
+                    XML_CHAR_TO_OUSTRING( systemId ) ,
+                    XML_CHAR_TO_OUSTRING( notationName ) ) );
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list