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)

xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
 /*
     * Is there any DTD definition ?
     */
 if (RAW == '[') {
        ctxt->instate = XML_PARSER_DTD;
        NEXT;
 /*
	 * Parse the succession of Markup declarations and
	 * PEReferences.
	 * Subsequence (markupdecl | PEReference | S)*
	 */
 while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) {
 const xmlChar *check = CUR_PTR;
 unsigned int cons = ctxt->input->consumed;

	    SKIP_BLANKS;
	    xmlParseMarkupDecl(ctxt);
	    xmlParsePEReference(ctxt);

 /*
	     * Pop-up of finished entities.
	     */
 while ((RAW == 0) && (ctxt->inputNr > 1))
		xmlPopInput(ctxt);

 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
		xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
 "xmlParseInternalSubset: error detected in Markup declaration\n");
 break;
 }
 }
 if (RAW == ']') {
	    NEXT;
	    SKIP_BLANKS;
 }
 }

 /*
     * We should be at the end of the DOCTYPE declaration.
     */
 if (RAW != '>') {
	xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);
 return;
 }
    NEXT;
}

xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
 /*
     * Is there any DTD definition ?
     */
 if (RAW == '[') {
        ctxt->instate = XML_PARSER_DTD;
        NEXT;
 /*
	 * Parse the succession of Markup declarations and
	 * PEReferences.
	 * Subsequence (markupdecl | PEReference | S)*
	 */
 while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) {
 const xmlChar *check = CUR_PTR;
 unsigned int cons = ctxt->input->consumed;

	    SKIP_BLANKS;
	    xmlParseMarkupDecl(ctxt);
	    xmlParsePEReference(ctxt);

 /*
	     * Pop-up of finished entities.
	     */
 while ((RAW == 0) && (ctxt->inputNr > 1))
		xmlPopInput(ctxt);

 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
		xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
 "xmlParseInternalSubset: error detected in Markup declaration\n");
 break;
 }
 }
 if (RAW == ']') {
	    NEXT;
	    SKIP_BLANKS;
 }
 }

 /*
     * We should be at the end of the DOCTYPE declaration.
     */
 if (RAW != '>') {
	xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);
 return;
 }
    NEXT;
}
