From a409daaa0575e2e1db197a32fc95804736acf841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Boisnard?= Date: Thu, 18 Oct 2012 18:20:03 +0200 Subject: PFW: Prevent crash if subsystem structure missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BZ: 62524 If the XML file defining a subsystem is missing, the PFW crashes without any message. This patch fixes this issue. Change-Id: Ibc0e9d195a8207d41d25613f56d1c9740bf6c784 Signed-off-by: Frédéric Boisnard Reviewed-on: http://android.intel.com:8080/70698 Reviewed-by: Denneulin, Guillaume Reviewed-by: Rocard, KevinX Reviewed-by: Centelles, Sylvain Reviewed-by: Baron, Georges-henriX Tested-by: Dixon, CharlesX Reviewed-by: buildbot Tested-by: buildbot --- xmlserializer/XmlFileDocSource.cpp | 17 ++++++++++++++--- xmlserializer/XmlFileDocSource.h | 3 +++ xmlserializer/XmlStringDocSink.cpp | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'xmlserializer') diff --git a/xmlserializer/XmlFileDocSource.cpp b/xmlserializer/XmlFileDocSource.cpp index c8a0837..f1094f1 100644 --- a/xmlserializer/XmlFileDocSource.cpp +++ b/xmlserializer/XmlFileDocSource.cpp @@ -43,9 +43,7 @@ CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, const str bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext) { // Check that the doc has been created - if (!_pDoc) { - - serializingContext.setError("Could not parse file " + _strXmlInstanceFile); + if (!isParsable(serializingContext)) { return false; } @@ -84,6 +82,19 @@ bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext) return true; } +bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) const +{ + // Check that the doc has been created + if (!_pDoc) { + + serializingContext.setError("Could not parse file " + _strXmlInstanceFile); + + return false; + } + + return true; +} + bool CXmlFileDocSource::isInstanceDocumentValid() { #ifdef LIBXML_SCHEMAS_ENABLED diff --git a/xmlserializer/XmlFileDocSource.h b/xmlserializer/XmlFileDocSource.h index 3274b29..46c5230 100644 --- a/xmlserializer/XmlFileDocSource.h +++ b/xmlserializer/XmlFileDocSource.h @@ -40,6 +40,9 @@ public: // CXmlDocSource method implemented virtual bool populate(CXmlSerializingContext& serializingContext); + // Check that the file exists and is readable + virtual bool isParsable(CXmlSerializingContext& serializingContext) const; + private: // Validation of the document with the xsd file diff --git a/xmlserializer/XmlStringDocSink.cpp b/xmlserializer/XmlStringDocSink.cpp index a96a1ed..c38036d 100644 --- a/xmlserializer/XmlStringDocSink.cpp +++ b/xmlserializer/XmlStringDocSink.cpp @@ -41,6 +41,11 @@ bool CXmlStringDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingCo int iSize; xmlDocDumpFormatMemoryEnc(xmlDocSource.getDoc(), &pcDumpedDoc, &iSize, "UTF-8", 1); + if (!pcDumpedDoc) { + + return false; + } + _strResult.append((const char*)pcDumpedDoc); xmlFree(pcDumpedDoc); -- cgit v1.1