Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: third_party/libxml/src/parser.c

Issue 1752223002: Roll libxml to 2.9.3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-cherry-pick fprintf formatting fix. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * parser.c : an XML 1.0 parser, namespaces and validity support are mostly 2 * parser.c : an XML 1.0 parser, namespaces and validity support are mostly
3 * implemented on top of the SAX interfaces 3 * implemented on top of the SAX interfaces
4 * 4 *
5 * References: 5 * References:
6 * The XML specification: 6 * The XML specification:
7 * http://www.w3.org/TR/REC-xml 7 * http://www.w3.org/TR/REC-xml
8 * Original 1.0 version: 8 * Original 1.0 version:
9 * http://www.w3.org/TR/1998/REC-xml-19980210 9 * http://www.w3.org/TR/1998/REC-xml-19980210
10 * XML second edition working draft 10 * XML second edition working draft
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 #include "buf.h" 87 #include "buf.h"
88 #include "enc.h" 88 #include "enc.h"
89 89
90 static void 90 static void
91 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info); 91 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info);
92 92
93 static xmlParserCtxtPtr 93 static xmlParserCtxtPtr
94 xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID, 94 xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID,
95 const xmlChar *base, xmlParserCtxtPtr pctx); 95 const xmlChar *base, xmlParserCtxtPtr pctx);
96 96
97 static void xmlHaltParser(xmlParserCtxtPtr ctxt);
98
97 /************************************************************************ 99 /************************************************************************
98 * * 100 * *
99 * Arbitrary limits set in the parser. See XML_PARSE_HUGE * 101 * Arbitrary limits set in the parser. See XML_PARSE_HUGE *
100 * * 102 * *
101 ************************************************************************/ 103 ************************************************************************/
102 104
103 #define XML_PARSER_BIG_ENTITY 1000 105 #define XML_PARSER_BIG_ENTITY 1000
104 #define XML_PARSER_LOT_ENTITY 5000 106 #define XML_PARSER_LOT_ENTITY 5000
105 107
106 /* 108 /*
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 return (-1); 1766 return (-1);
1765 } 1767 }
1766 ctxt->nodeTab = tmp; 1768 ctxt->nodeTab = tmp;
1767 ctxt->nodeMax *= 2; 1769 ctxt->nodeMax *= 2;
1768 } 1770 }
1769 if ((((unsigned int) ctxt->nodeNr) > xmlParserMaxDepth) && 1771 if ((((unsigned int) ctxt->nodeNr) > xmlParserMaxDepth) &&
1770 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 1772 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
1771 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR, 1773 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
1772 "Excessive depth in document: %d use XML_PARSE_HUGE option\n", 1774 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
1773 xmlParserMaxDepth); 1775 xmlParserMaxDepth);
1774 » ctxt->instate = XML_PARSER_EOF; 1776 » xmlHaltParser(ctxt);
1775 return(-1); 1777 return(-1);
1776 } 1778 }
1777 ctxt->nodeTab[ctxt->nodeNr] = value; 1779 ctxt->nodeTab[ctxt->nodeNr] = value;
1778 ctxt->node = value; 1780 ctxt->node = value;
1779 return (ctxt->nodeNr++); 1781 return (ctxt->nodeNr++);
1780 } 1782 }
1781 1783
1782 /** 1784 /**
1783 * nodePop: 1785 * nodePop:
1784 * @ctxt: an XML parser context 1786 * @ctxt: an XML parser context
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 2068
2067 static void xmlGROW (xmlParserCtxtPtr ctxt) { 2069 static void xmlGROW (xmlParserCtxtPtr ctxt) {
2068 unsigned long curEnd = ctxt->input->end - ctxt->input->cur; 2070 unsigned long curEnd = ctxt->input->end - ctxt->input->cur;
2069 unsigned long curBase = ctxt->input->cur - ctxt->input->base; 2071 unsigned long curBase = ctxt->input->cur - ctxt->input->base;
2070 2072
2071 if (((curEnd > (unsigned long) XML_MAX_LOOKUP_LIMIT) || 2073 if (((curEnd > (unsigned long) XML_MAX_LOOKUP_LIMIT) ||
2072 (curBase > (unsigned long) XML_MAX_LOOKUP_LIMIT)) && 2074 (curBase > (unsigned long) XML_MAX_LOOKUP_LIMIT)) &&
2073 ((ctxt->input->buf) && (ctxt->input->buf->readcallback != (xmlInputRead Callback) xmlNop)) && 2075 ((ctxt->input->buf) && (ctxt->input->buf->readcallback != (xmlInputRead Callback) xmlNop)) &&
2074 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 2076 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
2075 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup"); 2077 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
2076 ctxt->instate = XML_PARSER_EOF; 2078 xmlHaltParser(ctxt);
2079 » return;
2077 } 2080 }
2078 xmlParserInputGrow(ctxt->input, INPUT_CHUNK); 2081 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
2082 if ((ctxt->input->cur > ctxt->input->end) ||
2083 (ctxt->input->cur < ctxt->input->base)) {
2084 xmlHaltParser(ctxt);
2085 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "cur index out of bound");
2086 return;
2087 }
2079 if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) && 2088 if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) &&
2080 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) 2089 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
2081 xmlPopInput(ctxt); 2090 xmlPopInput(ctxt);
2082 } 2091 }
2083 2092
2084 #define SKIP_BLANKS xmlSkipBlankChars(ctxt) 2093 #define SKIP_BLANKS xmlSkipBlankChars(ctxt)
2085 2094
2086 #define NEXT xmlNextChar(ctxt) 2095 #define NEXT xmlNextChar(ctxt)
2087 2096
2088 #define NEXT1 { \ 2097 #define NEXT1 { \
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 ctxt->input->cur = cur; 2153 ctxt->input->cur = cur;
2145 xmlParserInputGrow(ctxt->input, INPUT_CHUNK); 2154 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
2146 cur = ctxt->input->cur; 2155 cur = ctxt->input->cur;
2147 } 2156 }
2148 } 2157 }
2149 ctxt->input->cur = cur; 2158 ctxt->input->cur = cur;
2150 } else { 2159 } else {
2151 int cur; 2160 int cur;
2152 do { 2161 do {
2153 cur = CUR; 2162 cur = CUR;
2154 » while (IS_BLANK_CH(cur)) { /* CHECKED tstblanks.xml */ 2163 » while ((IS_BLANK_CH(cur) && /* CHECKED tstblanks.xml */
2164 » (ctxt->instate != XML_PARSER_EOF))) {
2155 NEXT; 2165 NEXT;
2156 cur = CUR; 2166 cur = CUR;
2157 res++; 2167 res++;
2158 } 2168 }
2159 while ((cur == 0) && (ctxt->inputNr > 1) && 2169 while ((cur == 0) && (ctxt->inputNr > 1) &&
2160 (ctxt->instate != XML_PARSER_COMMENT)) { 2170 (ctxt->instate != XML_PARSER_COMMENT)) {
2161 xmlPopInput(ctxt); 2171 xmlPopInput(ctxt);
2162 cur = CUR; 2172 cur = CUR;
2163 } 2173 }
2164 /* 2174 /*
2165 * Need to handle support of entities branching here 2175 * Need to handle support of entities branching here
2166 */ 2176 */
2167 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); 2177 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);
2168 » } while (IS_BLANK(cur)); /* CHECKED tstblanks.xml */ 2178 » } while ((IS_BLANK(cur)) && /* CHECKED tstblanks.xml */
2179 » (ctxt->instate != XML_PARSER_EOF));
2169 } 2180 }
2170 return(res); 2181 return(res);
2171 } 2182 }
2172 2183
2173 /************************************************************************ 2184 /************************************************************************
2174 * * 2185 * *
2175 * Commodity functions to handle entities * 2186 * Commodity functions to handle entities *
2176 * * 2187 * *
2177 ************************************************************************/ 2188 ************************************************************************/
2178 2189
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 } else { 2810 } else {
2800 xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, 2811 xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
2801 "predefined entity has no content\n"); 2812 "predefined entity has no content\n");
2802 } 2813 }
2803 } else if ((ent != NULL) && (ent->content != NULL)) { 2814 } else if ((ent != NULL) && (ent->content != NULL)) {
2804 ctxt->depth++; 2815 ctxt->depth++;
2805 rep = xmlStringDecodeEntities(ctxt, ent->content, what, 2816 rep = xmlStringDecodeEntities(ctxt, ent->content, what,
2806 0, 0, 0); 2817 0, 0, 0);
2807 ctxt->depth--; 2818 ctxt->depth--;
2808 2819
2820 if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||
2821 (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
2822 goto int_error;
2823
2809 if (rep != NULL) { 2824 if (rep != NULL) {
2810 current = rep; 2825 current = rep;
2811 while (*current != 0) { /* non input consuming loop */ 2826 while (*current != 0) { /* non input consuming loop */
2812 buffer[nbchars++] = *current++; 2827 buffer[nbchars++] = *current++;
2813 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) { 2828 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2814 if (xmlParserEntityCheck(ctxt, nbchars, ent, 0)) 2829 if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
2815 goto int_error; 2830 goto int_error;
2816 growBuffer(buffer, XML_PARSER_BUFFER_SIZE); 2831 growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
2817 } 2832 }
2818 } 2833 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
3484 GROW; 3499 GROW;
3485 if (ctxt->instate == XML_PARSER_EOF) 3500 if (ctxt->instate == XML_PARSER_EOF)
3486 return(NULL); 3501 return(NULL);
3487 } 3502 }
3488 len += l; 3503 len += l;
3489 NEXTL(l); 3504 NEXTL(l);
3490 end = ctxt->input->cur; 3505 end = ctxt->input->cur;
3491 c = CUR_CHAR(l); 3506 c = CUR_CHAR(l);
3492 if (c == 0) { 3507 if (c == 0) {
3493 count = 0; 3508 count = 0;
3509 /*
3510 * when shrinking to extend the buffer we really need to preserve
3511 * the part of the name we already parsed. Hence rolling back
3512 * by current lenght.
3513 */
3514 ctxt->input->cur -= l;
3494 GROW; 3515 GROW;
3516 ctxt->input->cur += l;
3495 if (ctxt->instate == XML_PARSER_EOF) 3517 if (ctxt->instate == XML_PARSER_EOF)
3496 return(NULL); 3518 return(NULL);
3497 end = ctxt->input->cur; 3519 end = ctxt->input->cur;
3498 c = CUR_CHAR(l); 3520 c = CUR_CHAR(l);
3499 } 3521 }
3500 } 3522 }
3501 if ((len > XML_MAX_NAME_LENGTH) && 3523 if ((len > XML_MAX_NAME_LENGTH) &&
3502 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 3524 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3503 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); 3525 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3504 return(NULL); 3526 return(NULL);
(...skipping 11 matching lines...) Expand all
3516 * [4NS] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | 3538 * [4NS] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
3517 * CombiningChar | Extender 3539 * CombiningChar | Extender
3518 * 3540 *
3519 * [5NS] NCName ::= (Letter | '_') (NCNameChar)* 3541 * [5NS] NCName ::= (Letter | '_') (NCNameChar)*
3520 * 3542 *
3521 * Returns the Name parsed or NULL 3543 * Returns the Name parsed or NULL
3522 */ 3544 */
3523 3545
3524 static const xmlChar * 3546 static const xmlChar *
3525 xmlParseNCName(xmlParserCtxtPtr ctxt) { 3547 xmlParseNCName(xmlParserCtxtPtr ctxt) {
3526 const xmlChar *in; 3548 const xmlChar *in, *e;
3527 const xmlChar *ret; 3549 const xmlChar *ret;
3528 int count = 0; 3550 int count = 0;
3529 3551
3530 #ifdef DEBUG 3552 #ifdef DEBUG
3531 nbParseNCName++; 3553 nbParseNCName++;
3532 #endif 3554 #endif
3533 3555
3534 /* 3556 /*
3535 * Accelerator for simple ASCII names 3557 * Accelerator for simple ASCII names
3536 */ 3558 */
3537 in = ctxt->input->cur; 3559 in = ctxt->input->cur;
3538 if (((*in >= 0x61) && (*in <= 0x7A)) || 3560 e = ctxt->input->end;
3539 » ((*in >= 0x41) && (*in <= 0x5A)) || 3561 if ((((*in >= 0x61) && (*in <= 0x7A)) ||
3540 » (*in == '_')) { 3562 » ((*in >= 0x41) && (*in <= 0x5A)) ||
3563 » (*in == '_')) && (in < e)) {
3541 in++; 3564 in++;
3542 » while (((*in >= 0x61) && (*in <= 0x7A)) || 3565 » while ((((*in >= 0x61) && (*in <= 0x7A)) ||
3543 » ((*in >= 0x41) && (*in <= 0x5A)) || 3566 » ((*in >= 0x41) && (*in <= 0x5A)) ||
3544 » ((*in >= 0x30) && (*in <= 0x39)) || 3567 » ((*in >= 0x30) && (*in <= 0x39)) ||
3545 » (*in == '_') || (*in == '-') || 3568 » (*in == '_') || (*in == '-') ||
3546 » (*in == '.')) 3569 » (*in == '.')) && (in < e))
3547 in++; 3570 in++;
3571 if (in >= e)
3572 goto complex;
3548 if ((*in > 0) && (*in < 0x80)) { 3573 if ((*in > 0) && (*in < 0x80)) {
3549 count = in - ctxt->input->cur; 3574 count = in - ctxt->input->cur;
3550 if ((count > XML_MAX_NAME_LENGTH) && 3575 if ((count > XML_MAX_NAME_LENGTH) &&
3551 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 3576 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3552 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); 3577 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3553 return(NULL); 3578 return(NULL);
3554 } 3579 }
3555 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count); 3580 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
3556 ctxt->input->cur = in; 3581 ctxt->input->cur = in;
3557 ctxt->nbChars += count; 3582 ctxt->nbChars += count;
3558 ctxt->input->col += count; 3583 ctxt->input->col += count;
3559 if (ret == NULL) { 3584 if (ret == NULL) {
3560 xmlErrMemory(ctxt, NULL); 3585 xmlErrMemory(ctxt, NULL);
3561 } 3586 }
3562 return(ret); 3587 return(ret);
3563 } 3588 }
3564 } 3589 }
3590 complex:
3565 return(xmlParseNCNameComplex(ctxt)); 3591 return(xmlParseNCNameComplex(ctxt));
3566 } 3592 }
3567 3593
3568 /** 3594 /**
3569 * xmlParseNameAndCompare: 3595 * xmlParseNameAndCompare:
3570 * @ctxt: an XML parser context 3596 * @ctxt: an XML parser context
3571 * 3597 *
3572 * parse an XML name and compares for match 3598 * parse an XML name and compares for match
3573 * (specialized for endtag parsing) 3599 * (specialized for endtag parsing)
3574 * 3600 *
(...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after
5651 } 5677 }
5652 } 5678 }
5653 } 5679 }
5654 } 5680 }
5655 if (ctxt->instate == XML_PARSER_EOF) 5681 if (ctxt->instate == XML_PARSER_EOF)
5656 return; 5682 return;
5657 SKIP_BLANKS; 5683 SKIP_BLANKS;
5658 if (RAW != '>') { 5684 if (RAW != '>') {
5659 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED, 5685 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
5660 "xmlParseEntityDecl: entity %s not terminated\n", name); 5686 "xmlParseEntityDecl: entity %s not terminated\n", name);
5687 xmlHaltParser(ctxt);
5661 } else { 5688 } else {
5662 if (input != ctxt->input) { 5689 if (input != ctxt->input) {
5663 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, 5690 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5664 "Entity declaration doesn't start and stop in the same entity\n"); 5691 "Entity declaration doesn't start and stop in the same entity\n");
5665 } 5692 }
5666 NEXT; 5693 NEXT;
5667 } 5694 }
5668 if (orig != NULL) { 5695 if (orig != NULL) {
5669 /* 5696 /*
5670 * Ugly mechanism to save the raw entity value. 5697 * Ugly mechanism to save the raw entity value.
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
6762 xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { 6789 xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
6763 int id = ctxt->input->id; 6790 int id = ctxt->input->id;
6764 6791
6765 SKIP(3); 6792 SKIP(3);
6766 SKIP_BLANKS; 6793 SKIP_BLANKS;
6767 if (CMP7(CUR_PTR, 'I', 'N', 'C', 'L', 'U', 'D', 'E')) { 6794 if (CMP7(CUR_PTR, 'I', 'N', 'C', 'L', 'U', 'D', 'E')) {
6768 SKIP(7); 6795 SKIP(7);
6769 SKIP_BLANKS; 6796 SKIP_BLANKS;
6770 if (RAW != '[') { 6797 if (RAW != '[') {
6771 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL); 6798 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);
6799 xmlHaltParser(ctxt);
6800 return;
6772 } else { 6801 } else {
6773 if (ctxt->input->id != id) { 6802 if (ctxt->input->id != id) {
6774 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6803 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
6775 "All markup of the conditional section is not in the same entity\n", 6804 "All markup of the conditional section is not in the same entity\n",
6776 NULL, NULL); 6805 NULL, NULL);
6777 } 6806 }
6778 NEXT; 6807 NEXT;
6779 } 6808 }
6780 if (xmlParserDebugEntities) { 6809 if (xmlParserDebugEntities) {
6781 if ((ctxt->input != NULL) && (ctxt->input->filename)) 6810 if ((ctxt->input != NULL) && (ctxt->input->filename))
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6822 6851
6823 } else if (CMP6(CUR_PTR, 'I', 'G', 'N', 'O', 'R', 'E')) { 6852 } else if (CMP6(CUR_PTR, 'I', 'G', 'N', 'O', 'R', 'E')) {
6824 int state; 6853 int state;
6825 xmlParserInputState instate; 6854 xmlParserInputState instate;
6826 int depth = 0; 6855 int depth = 0;
6827 6856
6828 SKIP(6); 6857 SKIP(6);
6829 SKIP_BLANKS; 6858 SKIP_BLANKS;
6830 if (RAW != '[') { 6859 if (RAW != '[') {
6831 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL); 6860 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);
6861 xmlHaltParser(ctxt);
6862 return;
6832 } else { 6863 } else {
6833 if (ctxt->input->id != id) { 6864 if (ctxt->input->id != id) {
6834 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6865 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
6835 "All markup of the conditional section is not in the same entity\n", 6866 "All markup of the conditional section is not in the same entity\n",
6836 NULL, NULL); 6867 NULL, NULL);
6837 } 6868 }
6838 NEXT; 6869 NEXT;
6839 } 6870 }
6840 if (xmlParserDebugEntities) { 6871 if (xmlParserDebugEntities) {
6841 if ((ctxt->input != NULL) && (ctxt->input->filename)) 6872 if ((ctxt->input != NULL) && (ctxt->input->filename))
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6877 if ((ctxt->input != NULL) && (ctxt->input->filename)) 6908 if ((ctxt->input != NULL) && (ctxt->input->filename))
6878 xmlGenericError(xmlGenericErrorContext, 6909 xmlGenericError(xmlGenericErrorContext,
6879 "%s(%d): ", ctxt->input->filename, 6910 "%s(%d): ", ctxt->input->filename,
6880 ctxt->input->line); 6911 ctxt->input->line);
6881 xmlGenericError(xmlGenericErrorContext, 6912 xmlGenericError(xmlGenericErrorContext,
6882 "Leaving IGNORE Conditional Section\n"); 6913 "Leaving IGNORE Conditional Section\n");
6883 } 6914 }
6884 6915
6885 } else { 6916 } else {
6886 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL); 6917 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL);
6918 xmlHaltParser(ctxt);
6919 return;
6887 } 6920 }
6888 6921
6889 if (RAW == 0) 6922 if (RAW == 0)
6890 SHRINK; 6923 SHRINK;
6891 6924
6892 if (RAW == 0) { 6925 if (RAW == 0) {
6893 xmlFatalErr(ctxt, XML_ERR_CONDSEC_NOT_FINISHED, NULL); 6926 xmlFatalErr(ctxt, XML_ERR_CONDSEC_NOT_FINISHED, NULL);
6894 } else { 6927 } else {
6895 if (ctxt->input->id != id) { 6928 if (ctxt->input->id != id) {
6896 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6929 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
6897 "All markup of the conditional section is not in the same entity\n", 6930 "All markup of the conditional section is not in the same entity\n",
6898 NULL, NULL); 6931 NULL, NULL);
6899 } 6932 }
6900 SKIP(3); 6933 » if ((ctxt-> instate != XML_PARSER_EOF) &&
6934 » ((ctxt->input->cur + 3) <= ctxt->input->end))
6935 » SKIP(3);
6901 } 6936 }
6902 } 6937 }
6903 6938
6904 /** 6939 /**
6905 * xmlParseMarkupDecl: 6940 * xmlParseMarkupDecl:
6906 * @ctxt: an XML parser context 6941 * @ctxt: an XML parser context
6907 * 6942 *
6908 * parse Markup declarations 6943 * parse Markup declarations
6909 * 6944 *
6910 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | 6945 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6945 xmlParseComment(ctxt); 6980 xmlParseComment(ctxt);
6946 break; 6981 break;
6947 default: 6982 default:
6948 /* there is an error but it will be detected later */ 6983 /* there is an error but it will be detected later */
6949 break; 6984 break;
6950 } 6985 }
6951 } else if (NXT(1) == '?') { 6986 } else if (NXT(1) == '?') {
6952 xmlParsePI(ctxt); 6987 xmlParsePI(ctxt);
6953 } 6988 }
6954 } 6989 }
6990
6991 /*
6992 * detect requirement to exit there and act accordingly
6993 * and avoid having instate overriden later on
6994 */
6995 if (ctxt->instate == XML_PARSER_EOF)
6996 return;
6997
6955 /* 6998 /*
6956 * This is only for internal subset. On external entities, 6999 * This is only for internal subset. On external entities,
6957 * the replacement is done before parsing stage 7000 * the replacement is done before parsing stage
6958 */ 7001 */
6959 if ((ctxt->external == 0) && (ctxt->inputNr == 1)) 7002 if ((ctxt->external == 0) && (ctxt->inputNr == 1))
6960 xmlParsePEReference(ctxt); 7003 xmlParsePEReference(ctxt);
6961 7004
6962 /* 7005 /*
6963 * Conditional sections are allowed from entities included 7006 * Conditional sections are allowed from entities included
6964 * by PE References in the internal subset. 7007 * by PE References in the internal subset.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
7076 if (enc != XML_CHAR_ENCODING_NONE) 7119 if (enc != XML_CHAR_ENCODING_NONE)
7077 xmlSwitchEncoding(ctxt, enc); 7120 xmlSwitchEncoding(ctxt, enc);
7078 } 7121 }
7079 7122
7080 if (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) { 7123 if (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) {
7081 xmlParseTextDecl(ctxt); 7124 xmlParseTextDecl(ctxt);
7082 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { 7125 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
7083 /* 7126 /*
7084 * The XML REC instructs us to stop parsing right here 7127 * The XML REC instructs us to stop parsing right here
7085 */ 7128 */
7086 » ctxt->instate = XML_PARSER_EOF; 7129 » xmlHaltParser(ctxt);
7087 return; 7130 return;
7088 } 7131 }
7089 } 7132 }
7090 if (ctxt->myDoc == NULL) { 7133 if (ctxt->myDoc == NULL) {
7091 ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); 7134 ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0");
7092 if (ctxt->myDoc == NULL) { 7135 if (ctxt->myDoc == NULL) {
7093 xmlErrMemory(ctxt, "New Doc failed"); 7136 xmlErrMemory(ctxt, "New Doc failed");
7094 return; 7137 return;
7095 } 7138 }
7096 ctxt->myDoc->properties = XML_DOC_INTERNAL; 7139 ctxt->myDoc->properties = XML_DOC_INTERNAL;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
7228 /* 7271 /*
7229 * The first reference to the entity trigger a parsing phase 7272 * The first reference to the entity trigger a parsing phase
7230 * where the ent->children is filled with the result from 7273 * where the ent->children is filled with the result from
7231 * the parsing. 7274 * the parsing.
7232 * Note: external parsed entities will not be loaded, it is not 7275 * Note: external parsed entities will not be loaded, it is not
7233 * required for a non-validating parser, unless the parsing option 7276 * required for a non-validating parser, unless the parsing option
7234 * of validating, or substituting entities were given. Doing so is 7277 * of validating, or substituting entities were given. Doing so is
7235 * far more secure as the parser will only process data coming from 7278 * far more secure as the parser will only process data coming from
7236 * the document entity by default. 7279 * the document entity by default.
7237 */ 7280 */
7238 if ((ent->checked == 0) && 7281 if (((ent->checked == 0) ||
7282 ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&
7239 ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) || 7283 ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||
7240 (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) { 7284 (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {
7241 unsigned long oldnbent = ctxt->nbentities; 7285 unsigned long oldnbent = ctxt->nbentities;
7242 7286
7243 /* 7287 /*
7244 * This is a bit hackish but this seems the best 7288 * This is a bit hackish but this seems the best
7245 * way to make sure both SAX and DOM entity support 7289 * way to make sure both SAX and DOM entity support
7246 * behaves okay. 7290 * behaves okay.
7247 */ 7291 */
7248 void *user_data; 7292 void *user_data;
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
8062 if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && 8106 if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
8063 (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && 8107 (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) &&
8064 (IS_BLANK_CH(NXT(5)))) { 8108 (IS_BLANK_CH(NXT(5)))) {
8065 xmlParseTextDecl(ctxt); 8109 xmlParseTextDecl(ctxt);
8066 if (ctxt->errNo == 8110 if (ctxt->errNo ==
8067 XML_ERR_UNSUPPORTED_ENCODING) { 8111 XML_ERR_UNSUPPORTED_ENCODING) {
8068 /* 8112 /*
8069 * The XML REC instructs us to stop parsing 8113 * The XML REC instructs us to stop parsing
8070 * right here 8114 * right here
8071 */ 8115 */
8072 » » ctxt->instate = XML_PARSER_EOF; 8116 » » xmlHaltParser(ctxt);
8073 return; 8117 return;
8074 } 8118 }
8075 } 8119 }
8076 } 8120 }
8077 } 8121 }
8078 ctxt->hasPErefs = 1; 8122 ctxt->hasPErefs = 1;
8079 } 8123 }
8080 8124
8081 /** 8125 /**
8082 * xmlLoadEntityContent: 8126 * xmlLoadEntityContent:
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
8417 NEXT; 8461 NEXT;
8418 SKIP_BLANKS; 8462 SKIP_BLANKS;
8419 } 8463 }
8420 } 8464 }
8421 8465
8422 /* 8466 /*
8423 * We should be at the end of the DOCTYPE declaration. 8467 * We should be at the end of the DOCTYPE declaration.
8424 */ 8468 */
8425 if (RAW != '>') { 8469 if (RAW != '>') {
8426 xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL); 8470 xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);
8471 return;
8427 } 8472 }
8428 NEXT; 8473 NEXT;
8429 } 8474 }
8430 8475
8431 #ifdef LIBXML_SAX1_ENABLED 8476 #ifdef LIBXML_SAX1_ENABLED
8432 /** 8477 /**
8433 * xmlParseAttribute: 8478 * xmlParseAttribute:
8434 * @ctxt: an XML parser context 8479 * @ctxt: an XML parser context
8435 * @value: a xmlChar ** used to store the value of the attribute 8480 * @value: a xmlChar ** used to store the value of the attribute
8436 * 8481 *
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
9297 const xmlChar **URI, int *tlen) { 9342 const xmlChar **URI, int *tlen) {
9298 const xmlChar *localname; 9343 const xmlChar *localname;
9299 const xmlChar *prefix; 9344 const xmlChar *prefix;
9300 const xmlChar *attname; 9345 const xmlChar *attname;
9301 const xmlChar *aprefix; 9346 const xmlChar *aprefix;
9302 const xmlChar *nsname; 9347 const xmlChar *nsname;
9303 xmlChar *attvalue; 9348 xmlChar *attvalue;
9304 const xmlChar **atts = ctxt->atts; 9349 const xmlChar **atts = ctxt->atts;
9305 int maxatts = ctxt->maxatts; 9350 int maxatts = ctxt->maxatts;
9306 int nratts, nbatts, nbdef; 9351 int nratts, nbatts, nbdef;
9307 int i, j, nbNs, attval, oldline, oldcol; 9352 int i, j, nbNs, attval, oldline, oldcol, inputNr;
9308 const xmlChar *base; 9353 const xmlChar *base;
9309 unsigned long cur; 9354 unsigned long cur;
9310 int nsNr = ctxt->nsNr; 9355 int nsNr = ctxt->nsNr;
9311 9356
9312 if (RAW != '<') return(NULL); 9357 if (RAW != '<') return(NULL);
9313 NEXT1; 9358 NEXT1;
9314 9359
9315 /* 9360 /*
9316 * NOTE: it is crucial with the SAX2 API to never call SHRINK beyond that 9361 * NOTE: it is crucial with the SAX2 API to never call SHRINK beyond that
9317 * point since the attribute values may be stored as pointers to 9362 * point since the attribute values may be stored as pointers to
9318 * the buffer and calling SHRINK would destroy them ! 9363 * the buffer and calling SHRINK would destroy them !
9319 * The Shrinking is only possible once the full set of attribute 9364 * The Shrinking is only possible once the full set of attribute
9320 * callbacks have been done. 9365 * callbacks have been done.
9321 */ 9366 */
9322 reparse: 9367 reparse:
9323 SHRINK; 9368 SHRINK;
9324 base = ctxt->input->base; 9369 base = ctxt->input->base;
9325 cur = ctxt->input->cur - ctxt->input->base; 9370 cur = ctxt->input->cur - ctxt->input->base;
9371 inputNr = ctxt->inputNr;
9326 oldline = ctxt->input->line; 9372 oldline = ctxt->input->line;
9327 oldcol = ctxt->input->col; 9373 oldcol = ctxt->input->col;
9328 nbatts = 0; 9374 nbatts = 0;
9329 nratts = 0; 9375 nratts = 0;
9330 nbdef = 0; 9376 nbdef = 0;
9331 nbNs = 0; 9377 nbNs = 0;
9332 attval = 0; 9378 attval = 0;
9333 /* Forget any namespaces added during an earlier parse of this element. */ 9379 /* Forget any namespaces added during an earlier parse of this element. */
9334 ctxt->nsNr = nsNr; 9380 ctxt->nsNr = nsNr;
9335 9381
9336 localname = xmlParseQName(ctxt, &prefix); 9382 localname = xmlParseQName(ctxt, &prefix);
9337 if (localname == NULL) { 9383 if (localname == NULL) {
9338 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, 9384 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
9339 "StartTag: invalid element name\n"); 9385 "StartTag: invalid element name\n");
9340 return(NULL); 9386 return(NULL);
9341 } 9387 }
9342 *tlen = ctxt->input->cur - ctxt->input->base - cur; 9388 *tlen = ctxt->input->cur - ctxt->input->base - cur;
9343 9389
9344 /* 9390 /*
9345 * Now parse the attributes, it ends up with the ending 9391 * Now parse the attributes, it ends up with the ending
9346 * 9392 *
9347 * (S Attribute)* S? 9393 * (S Attribute)* S?
9348 */ 9394 */
9349 SKIP_BLANKS; 9395 SKIP_BLANKS;
9350 GROW; 9396 GROW;
9351 if (ctxt->input->base != base) goto base_changed; 9397 if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
9398 goto base_changed;
9352 9399
9353 while (((RAW != '>') && 9400 while (((RAW != '>') &&
9354 ((RAW != '/') || (NXT(1) != '>')) && 9401 ((RAW != '/') || (NXT(1) != '>')) &&
9355 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { 9402 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
9356 const xmlChar *q = CUR_PTR; 9403 const xmlChar *q = CUR_PTR;
9357 unsigned int cons = ctxt->input->consumed; 9404 unsigned int cons = ctxt->input->consumed;
9358 int len = -1, alloc = 0; 9405 int len = -1, alloc = 0;
9359 9406
9360 attname = xmlParseAttribute2(ctxt, prefix, localname, 9407 attname = xmlParseAttribute2(ctxt, prefix, localname,
9361 &aprefix, &attvalue, &len, &alloc); 9408 &aprefix, &attvalue, &len, &alloc);
9362 » if (ctxt->input->base != base) { 9409 » if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr)) {
9363 if ((attvalue != NULL) && (alloc != 0)) 9410 if ((attvalue != NULL) && (alloc != 0))
9364 xmlFree(attvalue); 9411 xmlFree(attvalue);
9365 attvalue = NULL; 9412 attvalue = NULL;
9366 goto base_changed; 9413 goto base_changed;
9367 } 9414 }
9368 if ((attname != NULL) && (attvalue != NULL)) { 9415 if ((attname != NULL) && (attvalue != NULL)) {
9369 if (len < 0) len = xmlStrlen(attvalue); 9416 if (len < 0) len = xmlStrlen(attvalue);
9370 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) { 9417 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
9371 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); 9418 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
9372 xmlURIPtr uri; 9419 xmlURIPtr uri;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
9501 skip_ns: 9548 skip_ns:
9502 if (alloc != 0) xmlFree(attvalue); 9549 if (alloc != 0) xmlFree(attvalue);
9503 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) 9550 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9504 break; 9551 break;
9505 if (!IS_BLANK_CH(RAW)) { 9552 if (!IS_BLANK_CH(RAW)) {
9506 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 9553 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9507 "attributes construct error\n"); 9554 "attributes construct error\n");
9508 break; 9555 break;
9509 } 9556 }
9510 SKIP_BLANKS; 9557 SKIP_BLANKS;
9511 » » if (ctxt->input->base != base) goto base_changed; 9558 » » if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
9559 » » goto base_changed;
9512 continue; 9560 continue;
9513 } 9561 }
9514 9562
9515 /* 9563 /*
9516 * Add the pair to atts 9564 * Add the pair to atts
9517 */ 9565 */
9518 if ((atts == NULL) || (nbatts + 5 > maxatts)) { 9566 if ((atts == NULL) || (nbatts + 5 > maxatts)) {
9519 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) { 9567 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
9520 if (attvalue[len] == 0) 9568 if (attvalue[len] == 0)
9521 xmlFree(attvalue); 9569 xmlFree(attvalue);
(...skipping 16 matching lines...) Expand all
9538 } else { 9586 } else {
9539 if ((attvalue != NULL) && (attvalue[len] == 0)) 9587 if ((attvalue != NULL) && (attvalue[len] == 0))
9540 xmlFree(attvalue); 9588 xmlFree(attvalue);
9541 } 9589 }
9542 9590
9543 failed: 9591 failed:
9544 9592
9545 GROW 9593 GROW
9546 if (ctxt->instate == XML_PARSER_EOF) 9594 if (ctxt->instate == XML_PARSER_EOF)
9547 break; 9595 break;
9548 » if (ctxt->input->base != base) goto base_changed; 9596 » if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
9597 » goto base_changed;
9549 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) 9598 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9550 break; 9599 break;
9551 if (!IS_BLANK_CH(RAW)) { 9600 if (!IS_BLANK_CH(RAW)) {
9552 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 9601 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9553 "attributes construct error\n"); 9602 "attributes construct error\n");
9554 break; 9603 break;
9555 } 9604 }
9556 SKIP_BLANKS; 9605 SKIP_BLANKS;
9557 if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && 9606 if ((cons == ctxt->input->consumed) && (q == CUR_PTR) &&
9558 (attname == NULL) && (attvalue == NULL)) { 9607 (attname == NULL) && (attvalue == NULL)) {
9559 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, 9608 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
9560 "xmlParseStartTag: problem parsing attributes\n"); 9609 "xmlParseStartTag: problem parsing attributes\n");
9561 break; 9610 break;
9562 } 9611 }
9563 GROW; 9612 GROW;
9564 » if (ctxt->input->base != base) goto base_changed; 9613 » if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
9614 » goto base_changed;
9565 } 9615 }
9566 9616
9567 /* 9617 /*
9568 * The attributes defaulting 9618 * The attributes defaulting
9569 */ 9619 */
9570 if (ctxt->attsDefault != NULL) { 9620 if (ctxt->attsDefault != NULL) {
9571 xmlDefAttrsPtr defaults; 9621 xmlDefAttrsPtr defaults;
9572 9622
9573 defaults = xmlHashLookup2(ctxt->attsDefault, localname, prefix); 9623 defaults = xmlHashLookup2(ctxt->attsDefault, localname, prefix);
9574 if (defaults != NULL) { 9624 if (defaults != NULL) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
9721 9771
9722 base_changed: 9772 base_changed:
9723 /* 9773 /*
9724 * the attribute strings are valid iif the base didn't changed 9774 * the attribute strings are valid iif the base didn't changed
9725 */ 9775 */
9726 if (attval != 0) { 9776 if (attval != 0) {
9727 for (i = 3,j = 0; j < nratts;i += 5,j++) 9777 for (i = 3,j = 0; j < nratts;i += 5,j++)
9728 if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL)) 9778 if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL))
9729 xmlFree((xmlChar *) atts[i]); 9779 xmlFree((xmlChar *) atts[i]);
9730 } 9780 }
9781
9782 /*
9783 * We can't switch from one entity to another in the middle
9784 * of a start tag
9785 */
9786 if (inputNr != ctxt->inputNr) {
9787 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
9788 "Start tag doesn't start and stop in the same entity\n");
9789 return(NULL);
9790 }
9791
9731 ctxt->input->cur = ctxt->input->base + cur; 9792 ctxt->input->cur = ctxt->input->base + cur;
9732 ctxt->input->line = oldline; 9793 ctxt->input->line = oldline;
9733 ctxt->input->col = oldcol; 9794 ctxt->input->col = oldcol;
9734 if (ctxt->wellFormed == 1) { 9795 if (ctxt->wellFormed == 1) {
9735 goto reparse; 9796 goto reparse;
9736 } 9797 }
9737 return(NULL); 9798 return(NULL);
9738 } 9799 }
9739 9800
9740 /** 9801 /**
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
10002 /* 10063 /*
10003 * Pop-up of finished entities. 10064 * Pop-up of finished entities.
10004 */ 10065 */
10005 while ((RAW == 0) && (ctxt->inputNr > 1)) 10066 while ((RAW == 0) && (ctxt->inputNr > 1))
10006 xmlPopInput(ctxt); 10067 xmlPopInput(ctxt);
10007 SHRINK; 10068 SHRINK;
10008 10069
10009 if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { 10070 if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
10010 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, 10071 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
10011 "detected an error in element content\n"); 10072 "detected an error in element content\n");
10012 » ctxt->instate = XML_PARSER_EOF; 10073 » xmlHaltParser(ctxt);
10013 break; 10074 break;
10014 } 10075 }
10015 } 10076 }
10016 } 10077 }
10017 10078
10018 /** 10079 /**
10019 * xmlParseElement: 10080 * xmlParseElement:
10020 * @ctxt: an XML parser context 10081 * @ctxt: an XML parser context
10021 * 10082 *
10022 * parse an XML element, this is highly recursive 10083 * parse an XML element, this is highly recursive
(...skipping 14 matching lines...) Expand all
10037 xmlParserNodeInfo node_info; 10098 xmlParserNodeInfo node_info;
10038 int line, tlen = 0; 10099 int line, tlen = 0;
10039 xmlNodePtr ret; 10100 xmlNodePtr ret;
10040 int nsNr = ctxt->nsNr; 10101 int nsNr = ctxt->nsNr;
10041 10102
10042 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) && 10103 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) &&
10043 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 10104 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
10044 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR, 10105 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
10045 "Excessive depth in document: %d use XML_PARSE_HUGE option\n", 10106 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
10046 xmlParserMaxDepth); 10107 xmlParserMaxDepth);
10047 » ctxt->instate = XML_PARSER_EOF; 10108 » xmlHaltParser(ctxt);
10048 return; 10109 return;
10049 } 10110 }
10050 10111
10051 /* Capture start position */ 10112 /* Capture start position */
10052 if (ctxt->record_info) { 10113 if (ctxt->record_info) {
10053 node_info.begin_pos = ctxt->input->consumed + 10114 node_info.begin_pos = ctxt->input->consumed +
10054 (CUR_PTR - ctxt->input->base); 10115 (CUR_PTR - ctxt->input->base);
10055 node_info.begin_line = ctxt->input->line; 10116 node_info.begin_line = ctxt->input->line;
10056 } 10117 }
10057 10118
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
10389 xmlFatalErr(ctxt, XML_ERR_EQUAL_REQUIRED, NULL); 10450 xmlFatalErr(ctxt, XML_ERR_EQUAL_REQUIRED, NULL);
10390 return(NULL); 10451 return(NULL);
10391 } 10452 }
10392 NEXT; 10453 NEXT;
10393 SKIP_BLANKS; 10454 SKIP_BLANKS;
10394 if (RAW == '"') { 10455 if (RAW == '"') {
10395 NEXT; 10456 NEXT;
10396 encoding = xmlParseEncName(ctxt); 10457 encoding = xmlParseEncName(ctxt);
10397 if (RAW != '"') { 10458 if (RAW != '"') {
10398 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); 10459 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);
10460 xmlFree((xmlChar *) encoding);
10461 return(NULL);
10399 } else 10462 } else
10400 NEXT; 10463 NEXT;
10401 } else if (RAW == '\''){ 10464 } else if (RAW == '\''){
10402 NEXT; 10465 NEXT;
10403 encoding = xmlParseEncName(ctxt); 10466 encoding = xmlParseEncName(ctxt);
10404 if (RAW != '\'') { 10467 if (RAW != '\'') {
10405 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); 10468 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);
10469 xmlFree((xmlChar *) encoding);
10470 return(NULL);
10406 } else 10471 } else
10407 NEXT; 10472 NEXT;
10408 } else { 10473 } else {
10409 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); 10474 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL);
10410 } 10475 }
10411 10476
10412 /* 10477 /*
10413 * Non standard parsing, allowing the user to ignore encoding 10478 * Non standard parsing, allowing the user to ignore encoding
10414 */ 10479 */
10415 if (ctxt->options & XML_PARSE_IGNORE_ENC) { 10480 if (ctxt->options & XML_PARSE_IGNORE_ENC) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
10452 } 10517 }
10453 else if (encoding != NULL) { 10518 else if (encoding != NULL) {
10454 xmlCharEncodingHandlerPtr handler; 10519 xmlCharEncodingHandlerPtr handler;
10455 10520
10456 if (ctxt->input->encoding != NULL) 10521 if (ctxt->input->encoding != NULL)
10457 xmlFree((xmlChar *) ctxt->input->encoding); 10522 xmlFree((xmlChar *) ctxt->input->encoding);
10458 ctxt->input->encoding = encoding; 10523 ctxt->input->encoding = encoding;
10459 10524
10460 handler = xmlFindCharEncodingHandler((const char *) encoding); 10525 handler = xmlFindCharEncodingHandler((const char *) encoding);
10461 if (handler != NULL) { 10526 if (handler != NULL) {
10462 » » xmlSwitchToEncoding(ctxt, handler); 10527 » » if (xmlSwitchToEncoding(ctxt, handler) < 0) {
10528 » » /* failed to convert */
10529 » » ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
10530 » » return(NULL);
10531 » » }
10463 } else { 10532 } else {
10464 xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING, 10533 xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
10465 "Unsupported encoding %s\n", encoding); 10534 "Unsupported encoding %s\n", encoding);
10466 return(NULL); 10535 return(NULL);
10467 } 10536 }
10468 } 10537 }
10469 } 10538 }
10470 return(encoding); 10539 return(encoding);
10471 } 10540 }
10472 10541
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
10621 * We may have the encoding declaration 10690 * We may have the encoding declaration
10622 */ 10691 */
10623 if (!IS_BLANK_CH(RAW)) { 10692 if (!IS_BLANK_CH(RAW)) {
10624 if ((RAW == '?') && (NXT(1) == '>')) { 10693 if ((RAW == '?') && (NXT(1) == '>')) {
10625 SKIP(2); 10694 SKIP(2);
10626 return; 10695 return;
10627 } 10696 }
10628 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n"); 10697 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n");
10629 } 10698 }
10630 xmlParseEncodingDecl(ctxt); 10699 xmlParseEncodingDecl(ctxt);
10631 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { 10700 if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
10701 (ctxt->instate == XML_PARSER_EOF)) {
10632 /* 10702 /*
10633 * The XML REC instructs us to stop parsing right here 10703 * The XML REC instructs us to stop parsing right here
10634 */ 10704 */
10635 return; 10705 return;
10636 } 10706 }
10637 10707
10638 /* 10708 /*
10639 * We may have the standalone status. 10709 * We may have the standalone status.
10640 */ 10710 */
10641 if ((ctxt->input->encoding != NULL) && (!IS_BLANK_CH(RAW))) { 10711 if ((ctxt->input->encoding != NULL) && (!IS_BLANK_CH(RAW))) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
10745 start[3] = NXT(3); 10815 start[3] = NXT(3);
10746 enc = xmlDetectCharEncoding(&start[0], 4); 10816 enc = xmlDetectCharEncoding(&start[0], 4);
10747 if (enc != XML_CHAR_ENCODING_NONE) { 10817 if (enc != XML_CHAR_ENCODING_NONE) {
10748 xmlSwitchEncoding(ctxt, enc); 10818 xmlSwitchEncoding(ctxt, enc);
10749 } 10819 }
10750 } 10820 }
10751 10821
10752 10822
10753 if (CUR == 0) { 10823 if (CUR == 0) {
10754 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); 10824 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
10825 return(-1);
10755 } 10826 }
10756 10827
10757 /* 10828 /*
10758 * Check for the XMLDecl in the Prolog. 10829 * Check for the XMLDecl in the Prolog.
10759 * do not GROW here to avoid the detected encoder to decode more 10830 * do not GROW here to avoid the detected encoder to decode more
10760 * than just the first line, unless the amount of data is really 10831 * than just the first line, unless the amount of data is really
10761 * too small to hold "<?xml version="1.0" encoding="foo" 10832 * too small to hold "<?xml version="1.0" encoding="foo"
10762 */ 10833 */
10763 if ((ctxt->input->end - ctxt->input->cur) < 35) { 10834 if ((ctxt->input->end - ctxt->input->cur) < 35) {
10764 GROW; 10835 GROW;
10765 } 10836 }
10766 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { 10837 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
10767 10838
10768 /* 10839 /*
10769 * Note that we will switch encoding on the fly. 10840 * Note that we will switch encoding on the fly.
10770 */ 10841 */
10771 xmlParseXMLDecl(ctxt); 10842 xmlParseXMLDecl(ctxt);
10772 » if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { 10843 » if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
10844 » (ctxt->instate == XML_PARSER_EOF)) {
10773 /* 10845 /*
10774 * The XML REC instructs us to stop parsing right here 10846 * The XML REC instructs us to stop parsing right here
10775 */ 10847 */
10776 return(-1); 10848 return(-1);
10777 } 10849 }
10778 ctxt->standalone = ctxt->input->standalone; 10850 ctxt->standalone = ctxt->input->standalone;
10779 SKIP_BLANKS; 10851 SKIP_BLANKS;
10780 } else { 10852 } else {
10781 ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); 10853 ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION);
10782 } 10854 }
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
11158 for (ix = 0; ix < len;) { /* string is 0-terminated */ 11230 for (ix = 0; ix < len;) { /* string is 0-terminated */
11159 c = utf[ix]; 11231 c = utf[ix];
11160 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */ 11232 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */
11161 if (c >= 0x20) 11233 if (c >= 0x20)
11162 ix++; 11234 ix++;
11163 else if ((c == 0xA) || (c == 0xD) || (c == 0x9)) 11235 else if ((c == 0xA) || (c == 0xD) || (c == 0x9))
11164 ix++; 11236 ix++;
11165 else 11237 else
11166 return(-ix); 11238 return(-ix);
11167 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */ 11239 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */
11168 » if (ix + 2 > len) return(ix); 11240 » if (ix + 2 > len) return(-ix);
11169 if ((utf[ix+1] & 0xc0 ) != 0x80) 11241 if ((utf[ix+1] & 0xc0 ) != 0x80)
11170 return(-ix); 11242 return(-ix);
11171 codepoint = (utf[ix] & 0x1f) << 6; 11243 codepoint = (utf[ix] & 0x1f) << 6;
11172 codepoint |= utf[ix+1] & 0x3f; 11244 codepoint |= utf[ix+1] & 0x3f;
11173 if (!xmlIsCharQ(codepoint)) 11245 if (!xmlIsCharQ(codepoint))
11174 return(-ix); 11246 return(-ix);
11175 ix += 2; 11247 ix += 2;
11176 } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */ 11248 } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */
11177 » if (ix + 3 > len) return(ix); 11249 » if (ix + 3 > len) return(-ix);
11178 if (((utf[ix+1] & 0xc0) != 0x80) || 11250 if (((utf[ix+1] & 0xc0) != 0x80) ||
11179 ((utf[ix+2] & 0xc0) != 0x80)) 11251 ((utf[ix+2] & 0xc0) != 0x80))
11180 return(-ix); 11252 return(-ix);
11181 codepoint = (utf[ix] & 0xf) << 12; 11253 codepoint = (utf[ix] & 0xf) << 12;
11182 codepoint |= (utf[ix+1] & 0x3f) << 6; 11254 codepoint |= (utf[ix+1] & 0x3f) << 6;
11183 codepoint |= utf[ix+2] & 0x3f; 11255 codepoint |= utf[ix+2] & 0x3f;
11184 if (!xmlIsCharQ(codepoint)) 11256 if (!xmlIsCharQ(codepoint))
11185 return(-ix); 11257 return(-ix);
11186 ix += 3; 11258 ix += 3;
11187 } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */ 11259 } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */
11188 » if (ix + 4 > len) return(ix); 11260 » if (ix + 4 > len) return(-ix);
11189 if (((utf[ix+1] & 0xc0) != 0x80) || 11261 if (((utf[ix+1] & 0xc0) != 0x80) ||
11190 ((utf[ix+2] & 0xc0) != 0x80) || 11262 ((utf[ix+2] & 0xc0) != 0x80) ||
11191 ((utf[ix+3] & 0xc0) != 0x80)) 11263 ((utf[ix+3] & 0xc0) != 0x80))
11192 return(-ix); 11264 return(-ix);
11193 codepoint = (utf[ix] & 0x7) << 18; 11265 codepoint = (utf[ix] & 0x7) << 18;
11194 codepoint |= (utf[ix+1] & 0x3f) << 12; 11266 codepoint |= (utf[ix+1] & 0x3f) << 12;
11195 codepoint |= (utf[ix+2] & 0x3f) << 6; 11267 codepoint |= (utf[ix+2] & 0x3f) << 6;
11196 codepoint |= utf[ix+3] & 0x3f; 11268 codepoint |= utf[ix+3] & 0x3f;
11197 if (!xmlIsCharQ(codepoint)) 11269 if (!xmlIsCharQ(codepoint))
11198 return(-ix); 11270 return(-ix);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
11356 11428
11357 if (avail < 2) 11429 if (avail < 2)
11358 goto done; 11430 goto done;
11359 cur = ctxt->input->cur[0]; 11431 cur = ctxt->input->cur[0];
11360 next = ctxt->input->cur[1]; 11432 next = ctxt->input->cur[1];
11361 if (cur == 0) { 11433 if (cur == 0) {
11362 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) 11434 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
11363 ctxt->sax->setDocumentLocator(ctxt->userData, 11435 ctxt->sax->setDocumentLocator(ctxt->userData,
11364 &xmlDefaultSAXLocator); 11436 &xmlDefaultSAXLocator);
11365 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); 11437 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
11366 » » ctxt->instate = XML_PARSER_EOF; 11438 » » xmlHaltParser(ctxt);
11367 #ifdef DEBUG_PUSH 11439 #ifdef DEBUG_PUSH
11368 xmlGenericError(xmlGenericErrorContext, 11440 xmlGenericError(xmlGenericErrorContext,
11369 "PP: entering EOF\n"); 11441 "PP: entering EOF\n");
11370 #endif 11442 #endif
11371 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11443 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11372 ctxt->sax->endDocument(ctxt->userData); 11444 ctxt->sax->endDocument(ctxt->userData);
11373 goto done; 11445 goto done;
11374 } 11446 }
11375 if ((cur == '<') && (next == '?')) { 11447 if ((cur == '<') && (next == '?')) {
11376 /* PI or XML decl */ 11448 /* PI or XML decl */
(...skipping 12 matching lines...) Expand all
11389 #ifdef DEBUG_PUSH 11461 #ifdef DEBUG_PUSH
11390 xmlGenericError(xmlGenericErrorContext, 11462 xmlGenericError(xmlGenericErrorContext,
11391 "PP: Parsing XML Decl\n"); 11463 "PP: Parsing XML Decl\n");
11392 #endif 11464 #endif
11393 xmlParseXMLDecl(ctxt); 11465 xmlParseXMLDecl(ctxt);
11394 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { 11466 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
11395 /* 11467 /*
11396 * The XML REC instructs us to stop parsing right 11468 * The XML REC instructs us to stop parsing right
11397 * here 11469 * here
11398 */ 11470 */
11399 » » » ctxt->instate = XML_PARSER_EOF; 11471 » » » xmlHaltParser(ctxt);
11400 return(0); 11472 return(0);
11401 } 11473 }
11402 ctxt->standalone = ctxt->input->standalone; 11474 ctxt->standalone = ctxt->input->standalone;
11403 if ((ctxt->encoding == NULL) && 11475 if ((ctxt->encoding == NULL) &&
11404 (ctxt->input->encoding != NULL)) 11476 (ctxt->input->encoding != NULL))
11405 ctxt->encoding = xmlStrdup(ctxt->input->encoding); 11477 ctxt->encoding = xmlStrdup(ctxt->input->encoding);
11406 if ((ctxt->sax) && (ctxt->sax->startDocument) && 11478 if ((ctxt->sax) && (ctxt->sax->startDocument) &&
11407 (!ctxt->disableSAX)) 11479 (!ctxt->disableSAX))
11408 ctxt->sax->startDocument(ctxt->userData); 11480 ctxt->sax->startDocument(ctxt->userData);
11409 ctxt->instate = XML_PARSER_MISC; 11481 ctxt->instate = XML_PARSER_MISC;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
11445 const xmlChar *name; 11517 const xmlChar *name;
11446 const xmlChar *prefix = NULL; 11518 const xmlChar *prefix = NULL;
11447 const xmlChar *URI = NULL; 11519 const xmlChar *URI = NULL;
11448 int nsNr = ctxt->nsNr; 11520 int nsNr = ctxt->nsNr;
11449 11521
11450 if ((avail < 2) && (ctxt->inputNr == 1)) 11522 if ((avail < 2) && (ctxt->inputNr == 1))
11451 goto done; 11523 goto done;
11452 cur = ctxt->input->cur[0]; 11524 cur = ctxt->input->cur[0];
11453 if (cur != '<') { 11525 if (cur != '<') {
11454 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL); 11526 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
11455 » » ctxt->instate = XML_PARSER_EOF; 11527 » » xmlHaltParser(ctxt);
11456 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11528 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11457 ctxt->sax->endDocument(ctxt->userData); 11529 ctxt->sax->endDocument(ctxt->userData);
11458 goto done; 11530 goto done;
11459 } 11531 }
11460 if (!terminate) { 11532 if (!terminate) {
11461 if (ctxt->progressive) { 11533 if (ctxt->progressive) {
11462 /* > can be found unescaped in attribute values */ 11534 /* > can be found unescaped in attribute values */
11463 if ((lastgt == NULL) || (ctxt->input->cur >= lastgt)) 11535 if ((lastgt == NULL) || (ctxt->input->cur >= lastgt))
11464 goto done; 11536 goto done;
11465 } else if (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0) { 11537 } else if (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0) {
(...skipping 11 matching lines...) Expand all
11477 #endif /* LIBXML_SAX1_ENABLED */ 11549 #endif /* LIBXML_SAX1_ENABLED */
11478 name = xmlParseStartTag2(ctxt, &prefix, &URI, &tlen); 11550 name = xmlParseStartTag2(ctxt, &prefix, &URI, &tlen);
11479 #ifdef LIBXML_SAX1_ENABLED 11551 #ifdef LIBXML_SAX1_ENABLED
11480 else 11552 else
11481 name = xmlParseStartTag(ctxt); 11553 name = xmlParseStartTag(ctxt);
11482 #endif /* LIBXML_SAX1_ENABLED */ 11554 #endif /* LIBXML_SAX1_ENABLED */
11483 if (ctxt->instate == XML_PARSER_EOF) 11555 if (ctxt->instate == XML_PARSER_EOF)
11484 goto done; 11556 goto done;
11485 if (name == NULL) { 11557 if (name == NULL) {
11486 spacePop(ctxt); 11558 spacePop(ctxt);
11487 » » ctxt->instate = XML_PARSER_EOF; 11559 » » xmlHaltParser(ctxt);
11488 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11560 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11489 ctxt->sax->endDocument(ctxt->userData); 11561 ctxt->sax->endDocument(ctxt->userData);
11490 goto done; 11562 goto done;
11491 } 11563 }
11492 #ifdef LIBXML_VALID_ENABLED 11564 #ifdef LIBXML_VALID_ENABLED
11493 /* 11565 /*
11494 * [ VC: Root Element Type ] 11566 * [ VC: Root Element Type ]
11495 * The Name in the document type declaration must match 11567 * The Name in the document type declaration must match
11496 * the element type of the root element. 11568 * the element type of the root element.
11497 */ 11569 */
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
11644 xmlParseCharData(ctxt, 0); 11716 xmlParseCharData(ctxt, 0);
11645 } 11717 }
11646 /* 11718 /*
11647 * Pop-up of finished entities. 11719 * Pop-up of finished entities.
11648 */ 11720 */
11649 while ((RAW == 0) && (ctxt->inputNr > 1)) 11721 while ((RAW == 0) && (ctxt->inputNr > 1))
11650 xmlPopInput(ctxt); 11722 xmlPopInput(ctxt);
11651 if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { 11723 if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
11652 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, 11724 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
11653 "detected an error in element content\n"); 11725 "detected an error in element content\n");
11654 » » ctxt->instate = XML_PARSER_EOF; 11726 » » xmlHaltParser(ctxt);
11655 break; 11727 break;
11656 } 11728 }
11657 break; 11729 break;
11658 } 11730 }
11659 case XML_PARSER_END_TAG: 11731 case XML_PARSER_END_TAG:
11660 if (avail < 2) 11732 if (avail < 2)
11661 goto done; 11733 goto done;
11662 if (!terminate) { 11734 if (!terminate) {
11663 if (ctxt->progressive) { 11735 if (ctxt->progressive) {
11664 /* > can be found unescaped in attribute values */ 11736 /* > can be found unescaped in attribute values */
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
11965 xmlParseComment(ctxt); 12037 xmlParseComment(ctxt);
11966 if (ctxt->instate == XML_PARSER_EOF) 12038 if (ctxt->instate == XML_PARSER_EOF)
11967 goto done; 12039 goto done;
11968 ctxt->instate = XML_PARSER_EPILOG; 12040 ctxt->instate = XML_PARSER_EPILOG;
11969 ctxt->progressive = 1; 12041 ctxt->progressive = 1;
11970 } else if ((cur == '<') && (next == '!') && 12042 } else if ((cur == '<') && (next == '!') &&
11971 (avail < 4)) { 12043 (avail < 4)) {
11972 goto done; 12044 goto done;
11973 } else { 12045 } else {
11974 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 12046 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11975 » » ctxt->instate = XML_PARSER_EOF; 12047 » » xmlHaltParser(ctxt);
11976 #ifdef DEBUG_PUSH 12048 #ifdef DEBUG_PUSH
11977 xmlGenericError(xmlGenericErrorContext, 12049 xmlGenericError(xmlGenericErrorContext,
11978 "PP: entering EOF\n"); 12050 "PP: entering EOF\n");
11979 #endif 12051 #endif
11980 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 12052 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11981 ctxt->sax->endDocument(ctxt->userData); 12053 ctxt->sax->endDocument(ctxt->userData);
11982 goto done; 12054 goto done;
11983 } 12055 }
11984 break; 12056 break;
11985 case XML_PARSER_DTD: { 12057 case XML_PARSER_DTD: {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
12329 if ((unsigned int) size > len) { 12401 if ((unsigned int) size > len) {
12330 remain = size - len; 12402 remain = size - len;
12331 size = len; 12403 size = len;
12332 } else { 12404 } else {
12333 remain = 0; 12405 remain = 0;
12334 } 12406 }
12335 } 12407 }
12336 res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); 12408 res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
12337 if (res < 0) { 12409 if (res < 0) {
12338 ctxt->errNo = XML_PARSER_EOF; 12410 ctxt->errNo = XML_PARSER_EOF;
12339 » ctxt->disableSAX = 1; 12411 » xmlHaltParser(ctxt);
12340 return (XML_PARSER_EOF); 12412 return (XML_PARSER_EOF);
12341 } 12413 }
12342 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur); 12414 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
12343 #ifdef DEBUG_PUSH 12415 #ifdef DEBUG_PUSH
12344 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 12416 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
12345 #endif 12417 #endif
12346 12418
12347 } else if (ctxt->instate != XML_PARSER_EOF) { 12419 } else if (ctxt->instate != XML_PARSER_EOF) {
12348 if ((ctxt->input != NULL) && ctxt->input->buf != NULL) { 12420 if ((ctxt->input != NULL) && ctxt->input->buf != NULL) {
12349 xmlParserInputBufferPtr in = ctxt->input->buf; 12421 xmlParserInputBufferPtr in = ctxt->input->buf;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
12383 xmlParseTryOrFinish(ctxt, terminate); 12455 xmlParseTryOrFinish(ctxt, terminate);
12384 } 12456 }
12385 if (ctxt->instate == XML_PARSER_EOF) 12457 if (ctxt->instate == XML_PARSER_EOF)
12386 return(ctxt->errNo); 12458 return(ctxt->errNo);
12387 12459
12388 if ((ctxt->input != NULL) && 12460 if ((ctxt->input != NULL) &&
12389 (((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) || 12461 (((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) ||
12390 ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) && 12462 ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
12391 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 12463 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
12392 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup"); 12464 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
12393 ctxt->instate = XML_PARSER_EOF; 12465 xmlHaltParser(ctxt);
12394 } 12466 }
12395 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 12467 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
12396 return(ctxt->errNo); 12468 return(ctxt->errNo);
12397 12469
12398 if (remain != 0) { 12470 if (remain != 0) {
12399 chunk += size; 12471 chunk += size;
12400 size = remain; 12472 size = remain;
12401 remain = 0; 12473 remain = 0;
12402 goto xmldecl_done; 12474 goto xmldecl_done;
12403 } 12475 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
12571 12643
12572 if (enc != XML_CHAR_ENCODING_NONE) { 12644 if (enc != XML_CHAR_ENCODING_NONE) {
12573 xmlSwitchEncoding(ctxt, enc); 12645 xmlSwitchEncoding(ctxt, enc);
12574 } 12646 }
12575 12647
12576 return(ctxt); 12648 return(ctxt);
12577 } 12649 }
12578 #endif /* LIBXML_PUSH_ENABLED */ 12650 #endif /* LIBXML_PUSH_ENABLED */
12579 12651
12580 /** 12652 /**
12653 * xmlHaltParser:
12654 * @ctxt: an XML parser context
12655 *
12656 * Blocks further parser processing don't override error
12657 * for internal use
12658 */
12659 static void
12660 xmlHaltParser(xmlParserCtxtPtr ctxt) {
12661 if (ctxt == NULL)
12662 return;
12663 ctxt->instate = XML_PARSER_EOF;
12664 ctxt->disableSAX = 1;
12665 if (ctxt->input != NULL) {
12666 /*
12667 * in case there was a specific allocation deallocate before
12668 * overriding base
12669 */
12670 if (ctxt->input->free != NULL) {
12671 ctxt->input->free((xmlChar *) ctxt->input->base);
12672 ctxt->input->free = NULL;
12673 }
12674 ctxt->input->cur = BAD_CAST"";
12675 ctxt->input->base = ctxt->input->cur;
12676 }
12677 }
12678
12679 /**
12581 * xmlStopParser: 12680 * xmlStopParser:
12582 * @ctxt: an XML parser context 12681 * @ctxt: an XML parser context
12583 * 12682 *
12584 * Blocks further parser processing 12683 * Blocks further parser processing
12585 */ 12684 */
12586 void 12685 void
12587 xmlStopParser(xmlParserCtxtPtr ctxt) { 12686 xmlStopParser(xmlParserCtxtPtr ctxt) {
12588 if (ctxt == NULL) 12687 if (ctxt == NULL)
12589 return; 12688 return;
12590 ctxt->instate = XML_PARSER_EOF; 12689 xmlHaltParser(ctxt);
12591 ctxt->errNo = XML_ERR_USER_STOP; 12690 ctxt->errNo = XML_ERR_USER_STOP;
12592 ctxt->disableSAX = 1;
12593 if (ctxt->input != NULL) {
12594 ctxt->input->cur = BAD_CAST"";
12595 ctxt->input->base = ctxt->input->cur;
12596 }
12597 } 12691 }
12598 12692
12599 /** 12693 /**
12600 * xmlCreateIOParserCtxt: 12694 * xmlCreateIOParserCtxt:
12601 * @sax: a SAX handler 12695 * @sax: a SAX handler
12602 * @user_data: The user data returned on SAX callbacks 12696 * @user_data: The user data returned on SAX callbacks
12603 * @ioread: an I/O read function 12697 * @ioread: an I/O read function
12604 * @ioclose: an I/O close function 12698 * @ioclose: an I/O close function
12605 * @ioctx: an I/O handler 12699 * @ioctx: an I/O handler
12606 * @enc: the charset encoding if known 12700 * @enc: the charset encoding if known
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
13333 /* 13427 /*
13334 * Record in the parent context the number of entities replacement 13428 * Record in the parent context the number of entities replacement
13335 * done when parsing that reference. 13429 * done when parsing that reference.
13336 */ 13430 */
13337 if (oldctxt != NULL) 13431 if (oldctxt != NULL)
13338 oldctxt->nbentities += ctxt->nbentities; 13432 oldctxt->nbentities += ctxt->nbentities;
13339 13433
13340 /* 13434 /*
13341 * Also record the size of the entity parsed 13435 * Also record the size of the entity parsed
13342 */ 13436 */
13343 if (ctxt->input != NULL) { 13437 if (ctxt->input != NULL && oldctxt != NULL) {
13344 oldctxt->sizeentities += ctxt->input->consumed; 13438 oldctxt->sizeentities += ctxt->input->consumed;
13345 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base); 13439 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base);
13346 } 13440 }
13347 /* 13441 /*
13348 * And record the last error if any 13442 * And record the last error if any
13349 */ 13443 */
13350 if (ctxt->lastError.code != XML_ERR_OK) 13444 if (ctxt->lastError.code != XML_ERR_OK)
13351 xmlCopyError(&ctxt->lastError, &oldctxt->lastError); 13445 xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
13352 13446
13353 if (sax != NULL) 13447 if (sax != NULL)
13354 ctxt->sax = oldsax; 13448 ctxt->sax = oldsax;
13355 oldctxt->node_seq.maximum = ctxt->node_seq.maximum; 13449 if (oldctxt != NULL) {
13356 oldctxt->node_seq.length = ctxt->node_seq.length; 13450 oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
13357 oldctxt->node_seq.buffer = ctxt->node_seq.buffer; 13451 oldctxt->node_seq.length = ctxt->node_seq.length;
13452 oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
13453 }
13358 ctxt->node_seq.maximum = 0; 13454 ctxt->node_seq.maximum = 0;
13359 ctxt->node_seq.length = 0; 13455 ctxt->node_seq.length = 0;
13360 ctxt->node_seq.buffer = NULL; 13456 ctxt->node_seq.buffer = NULL;
13361 xmlFreeParserCtxt(ctxt); 13457 xmlFreeParserCtxt(ctxt);
13362 newDoc->intSubset = NULL; 13458 newDoc->intSubset = NULL;
13363 newDoc->extSubset = NULL; 13459 newDoc->extSubset = NULL;
13364 xmlFreeDoc(newDoc); 13460 xmlFreeDoc(newDoc);
13365 13461
13366 return(ret); 13462 return(ret);
13367 } 13463 }
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
14823 #ifdef LIBXML_OUTPUT_ENABLED 14919 #ifdef LIBXML_OUTPUT_ENABLED
14824 xmlRegisterDefaultOutputCallbacks(); 14920 xmlRegisterDefaultOutputCallbacks();
14825 #endif /* LIBXML_OUTPUT_ENABLED */ 14921 #endif /* LIBXML_OUTPUT_ENABLED */
14826 #ifdef LIBXML_HTML_ENABLED 14922 #ifdef LIBXML_HTML_ENABLED
14827 htmlInitAutoClose(); 14923 htmlInitAutoClose();
14828 htmlDefaultSAXHandlerInit(); 14924 htmlDefaultSAXHandlerInit();
14829 #endif 14925 #endif
14830 #ifdef LIBXML_XPATH_ENABLED 14926 #ifdef LIBXML_XPATH_ENABLED
14831 xmlXPathInit(); 14927 xmlXPathInit();
14832 #endif 14928 #endif
14833 #ifdef LIBXML_CATALOG_ENABLED
14834 xmlInitializeCatalog();
14835 #endif
14836 xmlParserInitialized = 1; 14929 xmlParserInitialized = 1;
14837 #ifdef LIBXML_THREAD_ENABLED 14930 #ifdef LIBXML_THREAD_ENABLED
14838 } 14931 }
14839 __xmlGlobalInitMutexUnlock(); 14932 __xmlGlobalInitMutexUnlock();
14840 #endif 14933 #endif
14841 } 14934 }
14842 14935
14843 /** 14936 /**
14844 * xmlCleanupParser: 14937 * xmlCleanupParser:
14845 * 14938 *
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
15674 if (stream == NULL) { 15767 if (stream == NULL) {
15675 xmlFreeParserInputBuffer(input); 15768 xmlFreeParserInputBuffer(input);
15676 return (NULL); 15769 return (NULL);
15677 } 15770 }
15678 inputPush(ctxt, stream); 15771 inputPush(ctxt, stream);
15679 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15772 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15680 } 15773 }
15681 15774
15682 #define bottom_parser 15775 #define bottom_parser
15683 #include "elfgcchack.h" 15776 #include "elfgcchack.h"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698