From 9c684af4785a5fdbf2c3e1cbcc07eb3c7d3912e2 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Mon, 26 Sep 2016 18:08:36 +0200 Subject: [PATCH] handle unlikely situation that XML_ParserCreate() fails --- XML/src/ParserEngine.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/XML/src/ParserEngine.cpp b/XML/src/ParserEngine.cpp index 89c2385f1..bd1cdc5dd 100644 --- a/XML/src/ParserEngine.cpp +++ b/XML/src/ParserEngine.cpp @@ -450,19 +450,27 @@ void ParserEngine::init() if (dynamic_cast(_pNamespaceStrategy)) { _parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t'); - XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl); + if (_parser) + { + XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl); + } } else if (dynamic_cast(_pNamespaceStrategy)) { _parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t'); - XML_SetReturnNSTriplet(_parser, 1); - XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl); + if (_parser) + { + XML_SetReturnNSTriplet(_parser, 1); + XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl); + } } else { _parser = XML_ParserCreate(_encodingSpecified ? _encoding.c_str() : 0); } + if (!_parser) throw XMLException("Cannot create Expat parser"); + XML_SetUserData(_parser, this); XML_SetElementHandler(_parser, handleStartElement, handleEndElement); XML_SetCharacterDataHandler(_parser, handleCharacterData); @@ -720,6 +728,8 @@ int ParserEngine::handleExternalEntityRef(XML_Parser parser, const XML_Char* con if (pInputSource) { XML_Parser extParser = XML_ExternalEntityParserCreate(pThis->_parser, context, 0); + if (!extParser) throw XMLException("Cannot create external entity parser"); + try { pThis->parseExternal(extParser, pInputSource);