Commit d0b03aa2 authored by Alexandre Julliard's avatar Alexandre Julliard

xml2: Import upstream release 2.10.3.

parent fd3017ff
...@@ -5056,8 +5056,7 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt) ...@@ -5056,8 +5056,7 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
htmlErrMemory(NULL, "htmlInitParserCtxt: out of memory\n"); htmlErrMemory(NULL, "htmlInitParserCtxt: out of memory\n");
return(-1); return(-1);
} }
else memset(sax, 0, sizeof(htmlSAXHandler));
memset(sax, 0, sizeof(htmlSAXHandler));
/* Allocate the Input stack */ /* Allocate the Input stack */
ctxt->inputTab = (htmlParserInputPtr *) ctxt->inputTab = (htmlParserInputPtr *)
...@@ -5116,11 +5115,9 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt) ...@@ -5116,11 +5115,9 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
ctxt->nodeInfoNr = 0; ctxt->nodeInfoNr = 0;
ctxt->nodeInfoMax = 0; ctxt->nodeInfoMax = 0;
if (sax == NULL) ctxt->sax = (xmlSAXHandlerPtr) &htmlDefaultSAXHandler; ctxt->sax = sax;
else { xmlSAX2InitHtmlDefaultSAXHandler(sax);
ctxt->sax = sax;
memcpy(sax, &htmlDefaultSAXHandler, sizeof(xmlSAXHandlerV1));
}
ctxt->userData = ctxt; ctxt->userData = ctxt;
ctxt->myDoc = NULL; ctxt->myDoc = NULL;
ctxt->wellFormed = 1; ctxt->wellFormed = 1;
...@@ -7116,22 +7113,10 @@ htmlDocPtr ...@@ -7116,22 +7113,10 @@ htmlDocPtr
htmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar * cur, htmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar * cur,
const char *URL, const char *encoding, int options) const char *URL, const char *encoding, int options)
{ {
xmlParserInputPtr stream;
if (cur == NULL) if (cur == NULL)
return (NULL); return (NULL);
if (ctxt == NULL) return (htmlCtxtReadMemory(ctxt, (const char *) cur, xmlStrlen(cur), URL,
return (NULL); encoding, options));
xmlInitParser();
htmlCtxtReset(ctxt);
stream = xmlNewStringInputStream(ctxt, cur);
if (stream == NULL) {
return (NULL);
}
inputPush(ctxt, stream);
return (htmlDoRead(ctxt, URL, encoding, options, 1));
} }
/** /**
......
...@@ -28,11 +28,6 @@ ...@@ -28,11 +28,6 @@
#include <libxml/HTMLtree.h> #include <libxml/HTMLtree.h>
#include <libxml/globals.h> #include <libxml/globals.h>
/* Define SIZE_T_MAX unless defined through <limits.h>. */
#ifndef SIZE_T_MAX
# define SIZE_T_MAX ((size_t)-1)
#endif /* !SIZE_T_MAX */
/* #define DEBUG_SAX2 */ /* #define DEBUG_SAX2 */
/* #define DEBUG_SAX2_TREE */ /* #define DEBUG_SAX2_TREE */
...@@ -2596,22 +2591,23 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len, ...@@ -2596,22 +2591,23 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: xmlStrdup returned NULL"); xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: xmlStrdup returned NULL");
return; return;
} }
if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGTH) && if (ctxt->nodelen > INT_MAX - len) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
return;
}
if ((ctxt->nodelen + len > XML_MAX_TEXT_LENGTH) &&
((ctxt->options & XML_PARSE_HUGE) == 0)) { ((ctxt->options & XML_PARSE_HUGE) == 0)) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node"); xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node");
return; return;
} }
if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len ||
(size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
return;
}
if (ctxt->nodelen + len >= ctxt->nodemem) { if (ctxt->nodelen + len >= ctxt->nodemem) {
xmlChar *newbuf; xmlChar *newbuf;
size_t size; int size;
size = ctxt->nodemem + len; size = ctxt->nodemem > INT_MAX - len ?
size *= 2; INT_MAX :
ctxt->nodemem + len;
size = size > INT_MAX / 2 ? INT_MAX : size * 2;
newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
if (newbuf == NULL) { if (newbuf == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
......
...@@ -128,36 +128,19 @@ xmlFreeEntity(xmlEntityPtr entity) ...@@ -128,36 +128,19 @@ xmlFreeEntity(xmlEntityPtr entity)
if ((entity->children) && (entity->owner == 1) && if ((entity->children) && (entity->owner == 1) &&
(entity == (xmlEntityPtr) entity->children->parent)) (entity == (xmlEntityPtr) entity->children->parent))
xmlFreeNodeList(entity->children); xmlFreeNodeList(entity->children);
if (dict != NULL) { if ((entity->name != NULL) &&
if ((entity->name != NULL) && (!xmlDictOwns(dict, entity->name))) ((dict == NULL) || (!xmlDictOwns(dict, entity->name))))
xmlFree((char *) entity->name); xmlFree((char *) entity->name);
if ((entity->ExternalID != NULL) && if (entity->ExternalID != NULL)
(!xmlDictOwns(dict, entity->ExternalID))) xmlFree((char *) entity->ExternalID);
xmlFree((char *) entity->ExternalID); if (entity->SystemID != NULL)
if ((entity->SystemID != NULL) && xmlFree((char *) entity->SystemID);
(!xmlDictOwns(dict, entity->SystemID))) if (entity->URI != NULL)
xmlFree((char *) entity->SystemID); xmlFree((char *) entity->URI);
if ((entity->URI != NULL) && (!xmlDictOwns(dict, entity->URI))) if (entity->content != NULL)
xmlFree((char *) entity->URI); xmlFree((char *) entity->content);
if ((entity->content != NULL) if (entity->orig != NULL)
&& (!xmlDictOwns(dict, entity->content))) xmlFree((char *) entity->orig);
xmlFree((char *) entity->content);
if ((entity->orig != NULL) && (!xmlDictOwns(dict, entity->orig)))
xmlFree((char *) entity->orig);
} else {
if (entity->name != NULL)
xmlFree((char *) entity->name);
if (entity->ExternalID != NULL)
xmlFree((char *) entity->ExternalID);
if (entity->SystemID != NULL)
xmlFree((char *) entity->SystemID);
if (entity->URI != NULL)
xmlFree((char *) entity->URI);
if (entity->content != NULL)
xmlFree((char *) entity->content);
if (entity->orig != NULL)
xmlFree((char *) entity->orig);
}
xmlFree(entity); xmlFree(entity);
} }
...@@ -193,18 +176,12 @@ xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type, ...@@ -193,18 +176,12 @@ xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type,
ret->SystemID = xmlStrdup(SystemID); ret->SystemID = xmlStrdup(SystemID);
} else { } else {
ret->name = xmlDictLookup(dict, name, -1); ret->name = xmlDictLookup(dict, name, -1);
if (ExternalID != NULL) ret->ExternalID = xmlStrdup(ExternalID);
ret->ExternalID = xmlDictLookup(dict, ExternalID, -1); ret->SystemID = xmlStrdup(SystemID);
if (SystemID != NULL)
ret->SystemID = xmlDictLookup(dict, SystemID, -1);
} }
if (content != NULL) { if (content != NULL) {
ret->length = xmlStrlen(content); ret->length = xmlStrlen(content);
if ((dict != NULL) && (ret->length < 5)) ret->content = xmlStrndup(content, ret->length);
ret->content = (xmlChar *)
xmlDictLookup(dict, content, ret->length);
else
ret->content = xmlStrndup(content, ret->length);
} else { } else {
ret->length = 0; ret->length = 0;
ret->content = NULL; ret->content = NULL;
......
...@@ -15,9 +15,13 @@ ...@@ -15,9 +15,13 @@
#define HAVE_STDINT_H #define HAVE_STDINT_H
#endif #endif
#if defined(_MSC_VER) && _MSC_VER < 1900 #if defined(_MSC_VER)
#if _MSC_VER < 1900
#define snprintf _snprintf #define snprintf _snprintf
#define vsnprintf _vsnprintf #endif
#if _MSC_VER < 1500
#define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
#endif
#endif #endif
#endif /* __LIBXML_WIN32_CONFIG__ */ #endif /* __LIBXML_WIN32_CONFIG__ */
......
...@@ -9604,7 +9604,8 @@ xmlDOMWrapCloneNode(xmlDOMWrapCtxtPtr ctxt, ...@@ -9604,7 +9604,8 @@ xmlDOMWrapCloneNode(xmlDOMWrapCtxtPtr ctxt,
/* /*
* Attributes (xmlAttr). * Attributes (xmlAttr).
*/ */
clone = (xmlNodePtr) xmlMalloc(sizeof(xmlAttr)); /* Use xmlRealloc to avoid -Warray-bounds warning */
clone = (xmlNodePtr) xmlRealloc(NULL, sizeof(xmlAttr));
if (clone == NULL) { if (clone == NULL) {
xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating an attr-node"); xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating an attr-node");
goto internal_error; goto internal_error;
......
...@@ -10503,7 +10503,7 @@ xmlXPathCompFilterExpr(xmlXPathParserContextPtr ctxt) { ...@@ -10503,7 +10503,7 @@ xmlXPathCompFilterExpr(xmlXPathParserContextPtr ctxt) {
static xmlChar * static xmlChar *
xmlXPathScanName(xmlXPathParserContextPtr ctxt) { xmlXPathScanName(xmlXPathParserContextPtr ctxt) {
int len = 0, l; int l;
int c; int c;
const xmlChar *cur; const xmlChar *cur;
xmlChar *ret; xmlChar *ret;
...@@ -10523,7 +10523,6 @@ xmlXPathScanName(xmlXPathParserContextPtr ctxt) { ...@@ -10523,7 +10523,6 @@ xmlXPathScanName(xmlXPathParserContextPtr ctxt) {
(c == '_') || (c == ':') || (c == '_') || (c == ':') ||
(IS_COMBINING(c)) || (IS_COMBINING(c)) ||
(IS_EXTENDER(c)))) { (IS_EXTENDER(c)))) {
len += l;
NEXTL(l); NEXTL(l);
c = CUR_CHAR(l); c = CUR_CHAR(l);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment