DO NOT MERGE: Add validation for eternal enities

https://bugzilla.gnome.org/show_bug.cgi?id=780691

Bug: 36556310
Change-Id: I9450743e167c3c73af5e4071f3fc85e81d061648
(cherry picked from commit bef9af3d89d241bcb518c20cba6da2a2fd9ba049)

xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data,
 const char *filename) {
 int ret = 0;
    xmlParserCtxtPtr ctxt;

    ctxt = xmlCreateFileParserCtxt(filename);
 if (ctxt == NULL) return -1;
 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
	xmlFree(ctxt->sax);
    ctxt->sax = sax;
    xmlDetectSAX2(ctxt);

 if (user_data != NULL)
	ctxt->userData = user_data;

    xmlParseDocument(ctxt);

 if (ctxt->wellFormed)
	ret = 0;
 else {
 if (ctxt->errNo != 0)
	    ret = ctxt->errNo;
 else
	    ret = -1;
 }
 if (sax != NULL)
	ctxt->sax = NULL;
 if (ctxt->myDoc != NULL) {
        xmlFreeDoc(ctxt->myDoc);
	ctxt->myDoc = NULL;
 }
    xmlFreeParserCtxt(ctxt);

 return ret;
}

xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data,
 const char *filename) {
 int ret = 0;
    xmlParserCtxtPtr ctxt;

    ctxt = xmlCreateFileParserCtxt(filename);
 if (ctxt == NULL) return -1;
 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
	xmlFree(ctxt->sax);
    ctxt->sax = sax;
    xmlDetectSAX2(ctxt);

 if (user_data != NULL)
	ctxt->userData = user_data;

    xmlParseDocument(ctxt);

 if (ctxt->wellFormed)
	ret = 0;
 else {
 if (ctxt->errNo != 0)
	    ret = ctxt->errNo;
 else
	    ret = -1;
 }
 if (sax != NULL)
	ctxt->sax = NULL;
 if (ctxt->myDoc != NULL) {
        xmlFreeDoc(ctxt->myDoc);
	ctxt->myDoc = NULL;
 }
    xmlFreeParserCtxt(ctxt);

 return ret;
}
