[Libreoffice-commits] .: 2 commits - sax/source

Michael Stahl mst at kemper.freedesktop.org
Fri May 25 04:32:19 PDT 2012


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

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

    stop parsing on encountering internal entities in fastparser.cxx

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 66642e4..a320c90 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(
+    SAL_UNUSED_PARAMETER const XML_Char * /*entityName*/,
+    SAL_UNUSED_PARAMETER int /*is_parameter_entity*/,
+    const XML_Char *value, SAL_UNUSED_PARAMETER int /*value_length*/,
+    SAL_UNUSED_PARAMETER const XML_Char * /*base*/,
+    SAL_UNUSED_PARAMETER const XML_Char * /*systemId*/,
+    SAL_UNUSED_PARAMETER const XML_Char * /*publicId*/,
+    SAL_UNUSED_PARAMETER 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,
     SAL_UNUSED_PARAMETER const XML_Char * /*base*/, const XML_Char *systemId,
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 fe226fd8b1540ff9b29cb181b433c55d32803abd
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.

diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx
index 1e3d04d..360611f 100644
--- a/sax/source/expatwrap/sax_expat.cxx
+++ b/sax/source/expatwrap/sax_expat.cxx
@@ -271,12 +271,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,
@@ -323,14 +326,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,
@@ -495,8 +503,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);
@@ -844,20 +851,36 @@ void SaxExpatParser_Impl::callbackProcessingInstruction(    void *pvThis,
 }
 
 
-void SaxExpatParser_Impl::callbackUnparsedEntityDecl(
+void SaxExpatParser_Impl::callbackEntityDecl(
     void *pvThis, const XML_Char *entityName,
+    SAL_UNUSED_PARAMETER int /*is_parameter_entity*/,
+    const XML_Char *value, SAL_UNUSED_PARAMETER int /*value_length*/,
     SAL_UNUSED_PARAMETER 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