1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-28 00:21:53 +03:00

applied patch from Ashwin fixing a number of realloc problems improve

* uri.c: applied patch from Ashwin fixing a number of realloc problems
* HTMLparser.c: improve handling for misplaced html/head/body
Daniel

svn path=/trunk/; revision=3740
This commit is contained in:
Daniel Veillard
2008-04-24 11:58:41 +00:00
parent e9100a589d
commit ed86dc2383
3 changed files with 132 additions and 70 deletions

View File

@ -1,3 +1,8 @@
Thu Apr 24 13:56:53 CEST 2008 Daniel Veillard <daniel@veillard.com>
* uri.c: applied patch from Ashwin fixing a number of realloc problems
* HTMLparser.c: improve handling for misplaced html/head/body
Tue Apr 22 10:27:17 CEST 2008 Daniel Veillard <daniel@veillard.com> Tue Apr 22 10:27:17 CEST 2008 Daniel Veillard <daniel@veillard.com>
* dict.c: improvement on the hashing of the dictionnary, with visible * dict.c: improvement on the hashing of the dictionnary, with visible

View File

@ -3482,6 +3482,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
"htmlParseStartTag: misplaced <html> tag\n", "htmlParseStartTag: misplaced <html> tag\n",
name, NULL); name, NULL);
discardtag = 1; discardtag = 1;
ctxt->depth++;
} }
if ((ctxt->nameNr != 1) && if ((ctxt->nameNr != 1) &&
(xmlStrEqual(name, BAD_CAST"head"))) { (xmlStrEqual(name, BAD_CAST"head"))) {
@ -3489,6 +3490,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
"htmlParseStartTag: misplaced <head> tag\n", "htmlParseStartTag: misplaced <head> tag\n",
name, NULL); name, NULL);
discardtag = 1; discardtag = 1;
ctxt->depth++;
} }
if (xmlStrEqual(name, BAD_CAST"body")) { if (xmlStrEqual(name, BAD_CAST"body")) {
int indx; int indx;
@ -3498,6 +3500,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
"htmlParseStartTag: misplaced <body> tag\n", "htmlParseStartTag: misplaced <body> tag\n",
name, NULL); name, NULL);
discardtag = 1; discardtag = 1;
ctxt->depth++;
} }
} }
} }
@ -3648,7 +3651,6 @@ htmlParseEndTag(htmlParserCtxtPtr ctxt)
name = htmlParseHTMLName(ctxt); name = htmlParseHTMLName(ctxt);
if (name == NULL) if (name == NULL)
return (0); return (0);
/* /*
* We should definitely be at the ending "S? '>'" part * We should definitely be at the ending "S? '>'" part
*/ */
@ -3668,6 +3670,18 @@ htmlParseEndTag(htmlParserCtxtPtr ctxt)
} else } else
NEXT; NEXT;
/*
* if we ignored misplaced tags in htmlParseStartTag don't pop them
* out now.
*/
if ((ctxt->depth > 0) &&
(xmlStrEqual(name, BAD_CAST "html") ||
xmlStrEqual(name, BAD_CAST "body") ||
xmlStrEqual(name, BAD_CAST "head"))) {
ctxt->depth--;
return (0);
}
/* /*
* If the name read is not one of the element in the parsing stack * If the name read is not one of the element in the parsing stack
* then return, it's just an error. * then return, it's just an error.

181
uri.c
View File

@ -225,6 +225,7 @@ xmlCreateURI(void) {
xmlChar * xmlChar *
xmlSaveUri(xmlURIPtr uri) { xmlSaveUri(xmlURIPtr uri) {
xmlChar *ret = NULL; xmlChar *ret = NULL;
xmlChar *temp;
const char *p; const char *p;
int len; int len;
int max; int max;
@ -246,23 +247,27 @@ xmlSaveUri(xmlURIPtr uri) {
while (*p != 0) { while (*p != 0) {
if (len >= max) { if (len >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar)); temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ret[len++] = *p++; ret[len++] = *p++;
} }
if (len >= max) { if (len >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar)); temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ret[len++] = ':'; ret[len++] = ':';
} }
@ -271,12 +276,14 @@ xmlSaveUri(xmlURIPtr uri) {
while (*p != 0) { while (*p != 0) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar)); temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
ret[len++] = *p++; ret[len++] = *p++;
@ -292,12 +299,14 @@ xmlSaveUri(xmlURIPtr uri) {
if (uri->server != NULL) { if (uri->server != NULL) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar)); temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ret[len++] = '/'; ret[len++] = '/';
ret[len++] = '/'; ret[len++] = '/';
@ -306,13 +315,15 @@ xmlSaveUri(xmlURIPtr uri) {
while (*p != 0) { while (*p != 0) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
if ((IS_UNRESERVED(*(p))) || if ((IS_UNRESERVED(*(p))) ||
((*(p) == ';')) || ((*(p) == ':')) || ((*(p) == ';')) || ((*(p) == ':')) ||
@ -330,13 +341,15 @@ xmlSaveUri(xmlURIPtr uri) {
} }
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ret[len++] = '@'; ret[len++] = '@';
} }
@ -344,39 +357,45 @@ xmlSaveUri(xmlURIPtr uri) {
while (*p != 0) { while (*p != 0) {
if (len >= max) { if (len >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ret[len++] = *p++; ret[len++] = *p++;
} }
if (uri->port > 0) { if (uri->port > 0) {
if (len + 10 >= max) { if (len + 10 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
len += snprintf((char *) &ret[len], max - len, ":%d", uri->port); len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
} }
} else if (uri->authority != NULL) { } else if (uri->authority != NULL) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
ret[len++] = '/'; ret[len++] = '/';
ret[len++] = '/'; ret[len++] = '/';
@ -384,13 +403,15 @@ xmlSaveUri(xmlURIPtr uri) {
while (*p != 0) { while (*p != 0) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
if ((IS_UNRESERVED(*(p))) || if ((IS_UNRESERVED(*(p))) ||
((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) || ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
@ -408,13 +429,15 @@ xmlSaveUri(xmlURIPtr uri) {
} else if (uri->scheme != NULL) { } else if (uri->scheme != NULL) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
ret[len++] = '/'; ret[len++] = '/';
ret[len++] = '/'; ret[len++] = '/';
@ -448,13 +471,15 @@ xmlSaveUri(xmlURIPtr uri) {
while (*p != 0) { while (*p != 0) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) || if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) || ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
@ -473,52 +498,60 @@ xmlSaveUri(xmlURIPtr uri) {
if (uri->query_raw != NULL) { if (uri->query_raw != NULL) {
if (len + 1 >= max) { if (len + 1 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
ret[len++] = '?'; ret[len++] = '?';
p = uri->query_raw; p = uri->query_raw;
while (*p != 0) { while (*p != 0) {
if (len + 1 >= max) { if (len + 1 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ret[len++] = *p++; ret[len++] = *p++;
} }
} else if (uri->query != NULL) { } else if (uri->query != NULL) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
ret[len++] = '?'; ret[len++] = '?';
p = uri->query; p = uri->query;
while (*p != 0) { while (*p != 0) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
ret[len++] = *p++; ret[len++] = *p++;
@ -535,26 +568,30 @@ xmlSaveUri(xmlURIPtr uri) {
if (uri->fragment != NULL) { if (uri->fragment != NULL) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
ret[len++] = '#'; ret[len++] = '#';
p = uri->fragment; p = uri->fragment;
while (*p != 0) { while (*p != 0) {
if (len + 3 >= max) { if (len + 3 >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, temp = (xmlChar *) xmlRealloc(ret,
(max + 1) * sizeof(xmlChar)); (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
ret[len++] = *p++; ret[len++] = *p++;
@ -569,12 +606,14 @@ xmlSaveUri(xmlURIPtr uri) {
} }
if (len >= max) { if (len >= max) {
max *= 2; max *= 2;
ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar)); temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlSaveUri: out of memory\n"); "xmlSaveUri: out of memory\n");
return(NULL); xmlFree(ret);
} return(NULL);
}
ret = temp;
} }
ret[len++] = 0; ret[len++] = 0;
return(ret); return(ret);
@ -928,6 +967,7 @@ xmlURIUnescapeString(const char *str, int len, char *target) {
xmlChar * xmlChar *
xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) { xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
xmlChar *ret, ch; xmlChar *ret, ch;
xmlChar *temp;
const xmlChar *in; const xmlChar *in;
unsigned int len, out; unsigned int len, out;
@ -951,12 +991,14 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
while(*in != 0) { while(*in != 0) {
if (len - out <= 3) { if (len - out <= 3) {
len += 20; len += 20;
ret = (xmlChar *) xmlRealloc(ret, len); temp = (xmlChar *) xmlRealloc(ret, len);
if (ret == NULL) { if (temp == NULL) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlURIEscapeStr: out of memory\n"); "xmlURIEscapeStr: out of memory\n");
xmlFree(ret);
return(NULL); return(NULL);
} }
ret = temp;
} }
ch = *in; ch = *in;
@ -1009,7 +1051,8 @@ xmlURIEscape(const xmlChar * str)
#define NULLCHK(p) if(!p) { \ #define NULLCHK(p) if(!p) { \
xmlGenericError(xmlGenericErrorContext, \ xmlGenericError(xmlGenericErrorContext, \
"xmlURIEscape: out of memory\n"); \ "xmlURIEscape: out of memory\n"); \
return NULL; } xmlFreeURI(uri); \
return NULL; } \
if (str == NULL) if (str == NULL)
return (NULL); return (NULL);