Improve handling of XML errors for fix permissions

This commit is contained in:
Dees_Troy 2013-04-05 12:02:14 -05:00
parent 91862e618e
commit 34614eb94f
3 changed files with 36 additions and 13 deletions

View File

@ -443,15 +443,19 @@ int fixPermissions::getPackages() {
xmlFile.read(&xmlBuf[0], len); xmlFile.read(&xmlBuf[0], len);
xmlBuf[len] = '\0'; xmlBuf[len] = '\0';
xml_document<> pkgDoc; xml_document<> pkgDoc;
LOGINFO("parsing package, %i...\n", len);
pkgDoc.parse<parse_full>(&xmlBuf[0]); pkgDoc.parse<parse_full>(&xmlBuf[0]);
xml_node<> * pkgNode = pkgDoc.first_node("packages"); xml_node<> * pkgNode = pkgDoc.first_node("packages");
xml_node <> * next = pkgNode->first_node("package"); if (pkgNode == NULL) {
if (next == NULL) {
LOGERR("No packages found to fix.\n"); LOGERR("No packages found to fix.\n");
return -1; return -1;
} }
xml_node <> * next = pkgNode->first_node("package");
if (next == NULL) {
LOGERR("No package found to fix.\n");
return -1;
}
//Get packages //Get packages
while (next->first_attribute("name") != NULL) { while (next->first_attribute("name") != NULL) {

View File

@ -90,7 +90,8 @@ rapidxml::parse_error_handler (const char *what, void *where)
{ {
fprintf (stderr, "Parser error: %s\n", what); fprintf (stderr, "Parser error: %s\n", what);
fprintf (stderr, " Start of string: %s\n", (char *) where); fprintf (stderr, " Start of string: %s\n", (char *) where);
abort (); LOGERR("Error parsing XML file.\n");
//abort ();
} }
static void static void

View File

@ -1745,8 +1745,10 @@ namespace rapidxml
// Skip until end of declaration // Skip until end of declaration
while (text[0] != Ch('?') || text[1] != Ch('>')) while (text[0] != Ch('?') || text[1] != Ch('>'))
{ {
if (!text[0]) if (!text[0]) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
text += 2; // Skip '?>' text += 2; // Skip '?>'
@ -1780,8 +1782,10 @@ namespace rapidxml
// Skip until end of comment // Skip until end of comment
while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
{ {
if (!text[0]) if (!text[0]) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
text += 3; // Skip '-->' text += 3; // Skip '-->'
@ -1794,8 +1798,10 @@ namespace rapidxml
// Skip until end of comment // Skip until end of comment
while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
{ {
if (!text[0]) if (!text[0]) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
@ -1837,7 +1843,7 @@ namespace rapidxml
{ {
case Ch('['): ++depth; break; case Ch('['): ++depth; break;
case Ch(']'): --depth; break; case Ch(']'): --depth; break;
case 0: RAPIDXML_PARSE_ERROR("unexpected end of data", text); case 0: RAPIDXML_PARSE_ERROR("unexpected end of data", text); return 0;
} }
++text; ++text;
} }
@ -1847,6 +1853,7 @@ namespace rapidxml
// Error on end of text // Error on end of text
case Ch('\0'): case Ch('\0'):
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
// Other character, skip it // Other character, skip it
default: default:
@ -1903,8 +1910,10 @@ namespace rapidxml
// Skip to '?>' // Skip to '?>'
while (text[0] != Ch('?') || text[1] != Ch('>')) while (text[0] != Ch('?') || text[1] != Ch('>'))
{ {
if (*text == Ch('\0')) if (*text == Ch('\0')) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
@ -1926,8 +1935,10 @@ namespace rapidxml
// Skip to '?>' // Skip to '?>'
while (text[0] != Ch('?') || text[1] != Ch('>')) while (text[0] != Ch('?') || text[1] != Ch('>'))
{ {
if (*text == Ch('\0')) if (*text == Ch('\0')) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
text += 2; // Skip '?>' text += 2; // Skip '?>'
@ -2005,8 +2016,10 @@ namespace rapidxml
// Skip until end of cdata // Skip until end of cdata
while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
{ {
if (!text[0]) if (!text[0]) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
text += 3; // Skip ]]> text += 3; // Skip ]]>
@ -2017,8 +2030,10 @@ namespace rapidxml
Ch *value = text; Ch *value = text;
while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
{ {
if (!text[0]) if (!text[0]) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
@ -2154,8 +2169,10 @@ namespace rapidxml
++text; // Skip ! ++text; // Skip !
while (*text != Ch('>')) while (*text != Ch('>'))
{ {
if (*text == 0) if (*text == 0) {
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return 0;
}
++text; ++text;
} }
++text; // Skip '>' ++text; // Skip '>'
@ -2224,6 +2241,7 @@ namespace rapidxml
// End of data - error // End of data - error
case Ch('\0'): case Ch('\0'):
RAPIDXML_PARSE_ERROR("unexpected end of data", text); RAPIDXML_PARSE_ERROR("unexpected end of data", text);
return;
// Data node // Data node
default: default: