diff options
| author | Mike Hommey <glandium@debian.org> | 2009-03-01 10:55:27 +0100 |
|---|---|---|
| committer | Mike Hommey <glandium@debian.org> | 2009-03-01 10:55:27 +0100 |
| commit | e248b20a3b7df364cc9617b8685b4c190338bcd2 (patch) | |
| tree | f289c8584c4a44dd9cdb87003b193488da8b00f3 /SAX2.c | |
| parent | 0c8f97ec9edb09da2e0b19c4f9ddf8c725cebc59 (diff) | |
| download | libxml2-upstream/2.7.3.dfsg.tar.gz | |
Import upstream version 2.7.3upstream/2.7.3.dfsg
Diffstat (limited to 'SAX2.c')
| -rw-r--r-- | SAX2.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -11,6 +11,7 @@ #include "libxml.h" #include <stdlib.h> #include <string.h> +#include <limits.h> #include <libxml/xmlmemory.h> #include <libxml/tree.h> #include <libxml/parser.h> @@ -26,6 +27,11 @@ #include <libxml/HTMLtree.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_TREE */ @@ -2455,9 +2461,19 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, int len) (xmlDictOwns(ctxt->dict, lastChild->content))) { lastChild->content = xmlStrdup(lastChild->content); } + if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGTH) && + ((ctxt->options & XML_PARSE_HUGE) == 0)) { + xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node"); + 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) { xmlChar *newbuf; - int size; + size_t size; size = ctxt->nodemem + len; size *= 2; |
