Throw an exception if the received app list XML was incomplete

This commit is contained in:
Cameron Gutman 2015-02-26 17:58:03 -05:00
parent e6527de786
commit 8fb2622b66

View File

@ -328,6 +328,7 @@ public class NvHTTP {
int eventType = xpp.getEventType();
LinkedList<NvApp> appList = new LinkedList<NvApp>();
Stack<String> currentTag = new Stack<String>();
boolean rootTerminated = false;
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
@ -342,6 +343,9 @@ public class NvHTTP {
break;
case (XmlPullParser.END_TAG):
currentTag.pop();
if (xpp.getName().equals("root")) {
rootTerminated = true;
}
break;
case (XmlPullParser.TEXT):
NvApp app = appList.getLast();
@ -357,6 +361,11 @@ public class NvHTTP {
eventType = xpp.next();
}
// Throw a malformed XML exception if we've not seen the root tag ended
if (!rootTerminated) {
throw new XmlPullParserException("Malformed XML: Root tag was not terminated");
}
// Ensure that all apps in the list are initialized
ListIterator<NvApp> i = appList.listIterator();
while (i.hasNext()) {