OSDN Git Service

Add a check for a NULL root element from tinyxml2's XMLDocument.
authorSharvil Nanavati <sharvil@google.com>
Tue, 16 Sep 2014 07:11:35 +0000 (00:11 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 16 Mar 2015 23:51:33 +0000 (16:51 -0700)
This shouldn't really be necessary since a parsed document
should have at least a root element. In practice, however, tinyxml2
sometimes returns success on LoadFile() and NULL on RootElement().

Bug: 17504829

btif/src/btif_config_transcode.cpp

index 0888021..192e7dc 100644 (file)
@@ -35,13 +35,18 @@ extern "C" config_t *btif_config_transcode(const char *xml_filename) {
     return NULL;
   }
 
+  XMLElement *rootElement = document.RootElement();
+  if (!rootElement) {
+    ALOGE("%s unable to find root element; assuming corrupted config file.", __func__);
+    return NULL;
+  }
+
   config_t *config = config_new_empty();
   if (!config) {
     ALOGE("%s unable to allocate config object.", __func__);
     return NULL;
   }
 
-  XMLElement *rootElement = document.RootElement();
   for (XMLElement *i = rootElement->FirstChildElement(); i != NULL; i = i->NextSiblingElement())
     for (XMLElement *j = i->FirstChildElement(); j != NULL; j = j->NextSiblingElement()) {
       const char *section = j->Attribute("Tag");