diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-05-25 10:32:56 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-05-25 13:24:50 +0200 |
commit | cad983994944ca2cfcb27aa6e8a0181df63803b7 (patch) | |
tree | 80a0e42a842bff2a9123288aa1c687e5046eaaf3 /sax | |
parent | fe226fd8b1540ff9b29cb181b433c55d32803abd (diff) |
stop parsing on encountering internal entities in fastparser.cxx
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 36 | ||||
-rw-r--r-- | sax/source/fastparser/fastparser.hxx | 4 |
2 files changed, 40 insertions, 0 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 66642e475c49..a320c9032801 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 09a1d72be9ce..aac4e1dbbb6a 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(); } |