VirtualBox

Changeset 16778 in vbox for trunk/src/libs


Ignore:
Timestamp:
Feb 16, 2009 10:04:16 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
42849
Message:

libxml2: some fixes from upstream

Location:
trunk/src/libs/libxml2-2.6.30
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/libxml2-2.6.30/SAX2.c

    r6076 r16778  
    1212#include <stdlib.h>
    1313#include <string.h>
     14#include <limits.h>
    1415#include <libxml/xmlmemory.h>
    1516#include <libxml/tree.h>
     
    2627#include <libxml/HTMLtree.h>
    2728#include <libxml/globals.h>
     29
     30/* Define SIZE_T_MAX unless defined through <limits.h>. */
     31#ifndef SIZE_T_MAX
     32# define SIZE_T_MAX     ((size_t)-1)
     33#endif /* !SIZE_T_MAX */
    2834
    2935/* #define DEBUG_SAX2 */
     
    581587        }
    582588        ret->owner = 1;
    583         ret->checked = 1;
     589        if (ret->checked == 0)
     590            ret->checked = 1;
    584591    }
    585592    return(ret);
     
    24442451                lastChild->content = xmlStrdup(lastChild->content);
    24452452            }
     2453            if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len ||
     2454                (size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) {
     2455                xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
     2456                return;
     2457            }
    24462458            if (ctxt->nodelen + len >= ctxt->nodemem) {
    24472459                xmlChar *newbuf;
    2448                 int size;
     2460                size_t size;
    24492461
    24502462                size = ctxt->nodemem + len;
  • trunk/src/libs/libxml2-2.6.30/include/libxml/parser.h

    r6076 r16778  
    298298    xmlError          lastError;
    299299    xmlParserMode     parseMode;    /* the parser mode */
     300    unsigned long     nbentities;    /* number of entities references */
    300301};
    301302
  • trunk/src/libs/libxml2-2.6.30/parser.c

    r6076 r16778  
    21812181    last = str + len;
    21822182
    2183     if (ctxt->depth > 40) {
     2183    if ((ctxt->depth > 40) || (ctxt->nbentities >= 500000)) {
    21842184        xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
    21852185        return(NULL);
     
    22192219                        str);
    22202220            ent = xmlParseStringEntityRef(ctxt, &str);
     2221            if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
     2222                goto int_error;
     2223            ctxt->nbentities++;
     2224            if (ent != NULL)
     2225                ctxt->nbentities += ent->checked;
    22212226            if ((ent != NULL) &&
    22222227                (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
     
    22652270                        "String decoding PE Reference: %.30s\n", str);
    22662271            ent = xmlParseStringPEReference(ctxt, &str);
     2272            if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
     2273                goto int_error;
     2274            ctxt->nbentities++;
     2275            if (ent != NULL)
     2276                ctxt->nbentities += ent->checked;
    22672277            if (ent != NULL) {
    22682278                xmlChar *rep;
     
    23012311mem_error:
    23022312    xmlErrMemory(ctxt, NULL);
     2313int_error:
     2314    if (buffer != NULL)
     2315        xmlFree(buffer);
    23032316    return(NULL);
    23042317}
     
    31103123            } else {
    31113124                ent = xmlParseEntityRef(ctxt);
     3125                ctxt->nbentities++;
     3126                if (ent != NULL)
     3127                    ctxt->nbentities += ent->checked;
    31123128                if ((ent != NULL) &&
    31133129                    (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
     
    35843600                    col = ctxt->input->col;
    35853601                }
     3602                /* something really bad happened in the SAX callback */
     3603                if (ctxt->instate != XML_PARSER_CONTENT)
     3604                    return;
    35863605            }
    35873606            ctxt->input->cur = in;
     
    36643683            }
    36653684            nbchar = 0;
     3685            /* something really bad happened in the SAX callback */
     3686            if (ctxt->instate != XML_PARSER_CONTENT)
     3687                return;
    36663688        }
    36673689        count++;
     
    43924414    xmlChar *orig = NULL;
    43934415    int skipped;
     4416    unsigned long oldnbent = ctxt->nbentities;
    43944417   
    43954418    /* GROW; done in the caller */
     
    46014624            }
    46024625            if (cur != NULL) {
     4626                cur->checked = ctxt->nbentities - oldnbent;
    46034627                if (cur->orig != NULL)
    46044628                    xmlFree(orig);
     
    59796003        if (!ctxt->wellFormed)
    59806004            return;
     6005        ctxt->nbentities++;
     6006        if (ctxt->nbentities >= 500000) {
     6007            xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
     6008            return;
     6009        }
    59816010        was_checked = ent->checked;
    59826011        if ((ent->name != NULL) &&
     
    60396068                    }
    60406069                } else {
     6070                    unsigned long oldnbent = ctxt->nbentities;
    60416071                    /*
    60426072                     * 4.3.2: An internal general parsed entity is well-formed
     
    60736103                                     "invalid entity type found\n", NULL);
    60746104                    }
     6105                    ent->checked = ctxt->nbentities - oldnbent;
    60756106                    if (ret == XML_ERR_ENTITY_LOOP) {
    60766107                        xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
     
    61296160                    }
    61306161                }
    6131                 ent->checked = 1;
     6162                if (ent->checked == 0)
     6163                    ent->checked = 1;
    61326164            }
     6165            ctxt->nbentities += ent->checked;
    61336166
    61346167            if (ent->children == NULL) {
     
    61396172                 * content to generate callbacks associated to the entity
    61406173                 */
    6141                 if (was_checked == 1) {
     6174                if (was_checked != 0) {
    61426175                    void *user_data;
    61436176                    /*
     
    1115411187    if (ctx == NULL) return(-1);
    1115511188
    11156     if (ctx->depth > 40) {
     11189    if ((ctx->depth > 40) || (ctx->nbentities >= 500000)) {
    1115711190        return(XML_ERR_ENTITY_LOOP);
    1115811191    }
     
    1135511388    xmlCharEncoding enc;
    1135611389
    11357     if (depth > 40) {
     11390    if ((depth > 40) ||
     11391        ((oldctxt != NULL) && (oldctxt->nbentities >= 500000))) {
    1135811392        return(XML_ERR_ENTITY_LOOP);
    1135911393    }
     
    1149811532    oldctxt->node_seq.length = ctxt->node_seq.length;
    1149911533    oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
     11534    oldctxt->nbentities += ctxt->nbentities;
    1150011535    ctxt->node_seq.maximum = 0;
    1150111536    ctxt->node_seq.length = 0;
     
    1159811633    xmlParserErrors ret = XML_ERR_OK;
    1159911634
    11600     if (oldctxt->depth > 40) {
     11635    if ((oldctxt->depth > 40) || (oldctxt->nbentities >= 500000)) {
    1160111636        return(XML_ERR_ENTITY_LOOP);
    1160211637    }
     
    1172111756        ctxt->myDoc->last = last;
    1172211757    }
    11723        
     11758
     11759    oldctxt->nbentities += ctxt->nbentities;   
    1172411760    ctxt->sax = oldsax;
    1172511761    ctxt->dict = NULL;
     
    1303313069    ctxt->charset = XML_CHAR_ENCODING_UTF8;
    1303413070    ctxt->catalogs = NULL;
     13071    ctxt->nbentities = 0;
    1303513072    xmlInitNodeInfoSeq(&ctxt->node_seq);
    1303613073
  • trunk/src/libs/libxml2-2.6.30/parserInternals.c

    r6076 r16778  
    16581658    ctxt->charset = XML_CHAR_ENCODING_UTF8;
    16591659    ctxt->catalogs = NULL;
     1660    ctxt->nbentities = 0;
    16601661    xmlInitNodeInfoSeq(&ctxt->node_seq);
    16611662    return(0);
  • trunk/src/libs/libxml2-2.6.30/tree.c

    r6076 r16778  
    1515
    1616#include <string.h> /* for memset() only ! */
    17 
     17#include <limits.h>
    1818#ifdef HAVE_CTYPE_H
    1919#include <ctype.h>
     
    68996899        /*take care of empty case*/
    69006900        newSize = (buf->size ? buf->size*2 : size + 10);
    6901         while (size > newSize) newSize *= 2;
     6901        while (size > newSize) {
     6902            if (newSize > UINT_MAX / 2) {
     6903                xmlTreeErrMemory("growing buffer");
     6904                return 0;
     6905            }
     6906            newSize *= 2;
     6907        }
    69026908        break;
    69036909    case XML_BUFFER_ALLOC_EXACT:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette