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

Side by Side Diff: third_party/expat/files/lib/xmlparse.c.original

Issue 2761253002: Update expat to 2.2.0 to fix CVE vulnerability. (Closed)
Patch Set: update README.chromium Created 3 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
« no previous file with comments | « third_party/expat/files/lib/xmlparse.c ('k') | third_party/expat/files/lib/xmlrole.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd 1 /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission. 2 See the file COPYING for copying permission.
3 */ 3 */
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <string.h> /* memset(), memcpy() */ 6 #include <string.h> /* memset(), memcpy() */
7 #include <assert.h> 7 #include <assert.h>
8 #include <limits.h> /* UINT_MAX */ 8 #include <limits.h> /* UINT_MAX */
9 #include <time.h> /* time() */ 9
10 #ifdef WIN32
11 #define getpid GetCurrentProcessId
12 #else
13 #include <sys/time.h> /* gettimeofday() */
14 #include <sys/types.h> /* getpid() */
15 #include <unistd.h> /* getpid() */
16 #endif
10 17
11 #define XML_BUILDING_EXPAT 1 18 #define XML_BUILDING_EXPAT 1
12 19
13 #ifdef COMPILED_FROM_DSP 20 #ifdef WIN32
14 #include "winconfig.h" 21 #include "winconfig.h"
15 #elif defined(MACOS_CLASSIC) 22 #elif defined(MACOS_CLASSIC)
16 #include "macconfig.h" 23 #include "macconfig.h"
17 #elif defined(__amigaos__) 24 #elif defined(__amigaos__)
18 #include "amigaconfig.h" 25 #include "amigaconfig.h"
19 #elif defined(__WATCOMC__) 26 #elif defined(__WATCOMC__)
20 #include "watcomconfig.h" 27 #include "watcomconfig.h"
21 #elif defined(HAVE_EXPAT_CONFIG_H) 28 #elif defined(HAVE_EXPAT_CONFIG_H)
22 #include <expat_config.h> 29 #include <expat_config.h>
23 #endif /* ndef COMPILED_FROM_DSP */ 30 #endif /* ndef WIN32 */
24 31
25 #include "ascii.h" 32 #include "ascii.h"
26 #include "expat.h" 33 #include "expat.h"
27 34
28 #ifdef XML_UNICODE 35 #ifdef XML_UNICODE
29 #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX 36 #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX
30 #define XmlConvert XmlUtf16Convert 37 #define XmlConvert XmlUtf16Convert
31 #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding 38 #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding
32 #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS 39 #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS
33 #define XmlEncode XmlUtf16Encode 40 #define XmlEncode XmlUtf16Encode
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); 432 poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n);
426 static const XML_Char * FASTCALL 433 static const XML_Char * FASTCALL
427 poolAppendString(STRING_POOL *pool, const XML_Char *s); 434 poolAppendString(STRING_POOL *pool, const XML_Char *s);
428 435
429 static int FASTCALL nextScaffoldPart(XML_Parser parser); 436 static int FASTCALL nextScaffoldPart(XML_Parser parser);
430 static XML_Content * build_model(XML_Parser parser); 437 static XML_Content * build_model(XML_Parser parser);
431 static ELEMENT_TYPE * 438 static ELEMENT_TYPE *
432 getElementType(XML_Parser parser, const ENCODING *enc, 439 getElementType(XML_Parser parser, const ENCODING *enc,
433 const char *ptr, const char *end); 440 const char *ptr, const char *end);
434 441
435 static unsigned long generate_hash_secret_salt(void); 442 static unsigned long generate_hash_secret_salt(XML_Parser parser);
436 static XML_Bool startParsing(XML_Parser parser); 443 static XML_Bool startParsing(XML_Parser parser);
437 444
438 static XML_Parser 445 static XML_Parser
439 parserCreate(const XML_Char *encodingName, 446 parserCreate(const XML_Char *encodingName,
440 const XML_Memory_Handling_Suite *memsuite, 447 const XML_Memory_Handling_Suite *memsuite,
441 const XML_Char *nameSep, 448 const XML_Char *nameSep,
442 DTD *dtd); 449 DTD *dtd);
443 450
444 static void 451 static void
445 parserInit(XML_Parser parser, const XML_Char *encodingName); 452 parserInit(XML_Parser parser, const XML_Char *encodingName);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 static const XML_Char implicitContext[] = { 691 static const XML_Char implicitContext[] = {
685 ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, 692 ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p,
686 ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, 693 ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w,
687 ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, 694 ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g,
688 ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, 695 ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9,
689 ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, 696 ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e,
690 ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' 697 ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0'
691 }; 698 };
692 699
693 static unsigned long 700 static unsigned long
694 generate_hash_secret_salt(void) 701 gather_time_entropy(void)
695 { 702 {
696 unsigned int seed = time(NULL) % UINT_MAX; 703 #ifdef WIN32
697 srand(seed); 704 FILETIME ft;
698 return rand(); 705 GetSystemTimeAsFileTime(&ft); /* never fails */
706 return ft.dwHighDateTime ^ ft.dwLowDateTime;
707 #else
708 struct timeval tv;
709 int gettimeofday_res;
710
711 gettimeofday_res = gettimeofday(&tv, NULL);
712 assert (gettimeofday_res == 0);
713
714 /* Microseconds time is <20 bits entropy */
715 return tv.tv_usec;
716 #endif
717 }
718
719 static unsigned long
720 generate_hash_secret_salt(XML_Parser parser)
721 {
722 /* Process ID is 0 bits entropy if attacker has local access
723 * XML_Parser address is few bits of entropy if attacker has local access */
724 const unsigned long entropy =
725 gather_time_entropy() ^ getpid() ^ (unsigned long)parser;
726
727 /* Factors are 2^31-1 and 2^61-1 (Mersenne primes M31 and M61) */
728 if (sizeof(unsigned long) == 4) {
729 return entropy * 2147483647;
730 } else {
731 return entropy * (unsigned long)2305843009213693951;
732 }
699 } 733 }
700 734
701 static XML_Bool /* only valid for root parser */ 735 static XML_Bool /* only valid for root parser */
702 startParsing(XML_Parser parser) 736 startParsing(XML_Parser parser)
703 { 737 {
704 /* hash functions must be initialized before setContext() is called */ 738 /* hash functions must be initialized before setContext() is called */
705 if (hash_secret_salt == 0) 739 if (hash_secret_salt == 0)
706 hash_secret_salt = generate_hash_secret_salt(); 740 hash_secret_salt = generate_hash_secret_salt(parser);
707 if (ns) { 741 if (ns) {
708 /* implicit context only set for root parser, since child 742 /* implicit context only set for root parser, since child
709 parsers (i.e. external entity parsers) will inherit it 743 parsers (i.e. external entity parsers) will inherit it
710 */ 744 */
711 return setContext(parser, implicitContext); 745 return setContext(parser, implicitContext);
712 } 746 }
713 return XML_TRUE; 747 return XML_TRUE;
714 } 748 }
715 749
716 XML_Parser XMLCALL 750 XML_Parser XMLCALL
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 } 1577 }
1544 } 1578 }
1545 eventEndPtr = eventPtr; 1579 eventEndPtr = eventPtr;
1546 processor = errorProcessor; 1580 processor = errorProcessor;
1547 return XML_STATUS_ERROR; 1581 return XML_STATUS_ERROR;
1548 } 1582 }
1549 #ifndef XML_CONTEXT_BYTES 1583 #ifndef XML_CONTEXT_BYTES
1550 else if (bufferPtr == bufferEnd) { 1584 else if (bufferPtr == bufferEnd) {
1551 const char *end; 1585 const char *end;
1552 int nLeftOver; 1586 int nLeftOver;
1553 enum XML_Error result; 1587 enum XML_Status result;
1554 parseEndByteIndex += len; 1588 parseEndByteIndex += len;
1555 positionPtr = s; 1589 positionPtr = s;
1556 ps_finalBuffer = (XML_Bool)isFinal; 1590 ps_finalBuffer = (XML_Bool)isFinal;
1557 1591
1558 errorCode = processor(parser, s, parseEndPtr = s + len, &end); 1592 errorCode = processor(parser, s, parseEndPtr = s + len, &end);
1559 1593
1560 if (errorCode != XML_ERROR_NONE) { 1594 if (errorCode != XML_ERROR_NONE) {
1561 eventEndPtr = eventPtr; 1595 eventEndPtr = eventPtr;
1562 processor = errorProcessor; 1596 processor = errorProcessor;
1563 return XML_STATUS_ERROR; 1597 return XML_STATUS_ERROR;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 } 1705 }
1672 1706
1673 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1707 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
1674 positionPtr = bufferPtr; 1708 positionPtr = bufferPtr;
1675 return result; 1709 return result;
1676 } 1710 }
1677 1711
1678 void * XMLCALL 1712 void * XMLCALL
1679 XML_GetBuffer(XML_Parser parser, int len) 1713 XML_GetBuffer(XML_Parser parser, int len)
1680 { 1714 {
1715 if (len < 0) {
1716 errorCode = XML_ERROR_NO_MEMORY;
1717 return NULL;
1718 }
1681 switch (ps_parsing) { 1719 switch (ps_parsing) {
1682 case XML_SUSPENDED: 1720 case XML_SUSPENDED:
1683 errorCode = XML_ERROR_SUSPENDED; 1721 errorCode = XML_ERROR_SUSPENDED;
1684 return NULL; 1722 return NULL;
1685 case XML_FINISHED: 1723 case XML_FINISHED:
1686 errorCode = XML_ERROR_FINISHED; 1724 errorCode = XML_ERROR_FINISHED;
1687 return NULL; 1725 return NULL;
1688 default: ; 1726 default: ;
1689 } 1727 }
1690 1728
1691 if (len > bufferLim - bufferEnd) { 1729 if (len > bufferLim - bufferEnd) {
1692 /* FIXME avoid integer overflow */
1693 int neededSize = len + (int)(bufferEnd - bufferPtr);
1694 #ifdef XML_CONTEXT_BYTES 1730 #ifdef XML_CONTEXT_BYTES
1695 int keep = (int)(bufferPtr - buffer); 1731 int keep;
1696 1732 #endif /* defined XML_CONTEXT_BYTES */
1733 /* Do not invoke signed arithmetic overflow: */
1734 int neededSize = (int) ((unsigned)len + (unsigned)(bufferEnd - bufferPtr));
1735 if (neededSize < 0) {
1736 errorCode = XML_ERROR_NO_MEMORY;
1737 return NULL;
1738 }
1739 #ifdef XML_CONTEXT_BYTES
1740 keep = (int)(bufferPtr - buffer);
1697 if (keep > XML_CONTEXT_BYTES) 1741 if (keep > XML_CONTEXT_BYTES)
1698 keep = XML_CONTEXT_BYTES; 1742 keep = XML_CONTEXT_BYTES;
1699 neededSize += keep; 1743 neededSize += keep;
1700 #endif /* defined XML_CONTEXT_BYTES */ 1744 #endif /* defined XML_CONTEXT_BYTES */
1701 if (neededSize <= bufferLim - buffer) { 1745 if (neededSize <= bufferLim - buffer) {
1702 #ifdef XML_CONTEXT_BYTES 1746 #ifdef XML_CONTEXT_BYTES
1703 if (keep < bufferPtr - buffer) { 1747 if (keep < bufferPtr - buffer) {
1704 int offset = (int)(bufferPtr - buffer) - keep; 1748 int offset = (int)(bufferPtr - buffer) - keep;
1705 memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); 1749 memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);
1706 bufferEnd -= offset; 1750 bufferEnd -= offset;
1707 bufferPtr -= offset; 1751 bufferPtr -= offset;
1708 } 1752 }
1709 #else 1753 #else
1710 memmove(buffer, bufferPtr, bufferEnd - bufferPtr); 1754 memmove(buffer, bufferPtr, bufferEnd - bufferPtr);
1711 bufferEnd = buffer + (bufferEnd - bufferPtr); 1755 bufferEnd = buffer + (bufferEnd - bufferPtr);
1712 bufferPtr = buffer; 1756 bufferPtr = buffer;
1713 #endif /* not defined XML_CONTEXT_BYTES */ 1757 #endif /* not defined XML_CONTEXT_BYTES */
1714 } 1758 }
1715 else { 1759 else {
1716 char *newBuf; 1760 char *newBuf;
1717 int bufferSize = (int)(bufferLim - bufferPtr); 1761 int bufferSize = (int)(bufferLim - bufferPtr);
1718 if (bufferSize == 0) 1762 if (bufferSize == 0)
1719 bufferSize = INIT_BUFFER_SIZE; 1763 bufferSize = INIT_BUFFER_SIZE;
1720 do { 1764 do {
1721 bufferSize *= 2; 1765 /* Do not invoke signed arithmetic overflow: */
1722 } while (bufferSize < neededSize); 1766 bufferSize = (int) (2U * (unsigned) bufferSize);
1767 } while (bufferSize < neededSize && bufferSize > 0);
1768 if (bufferSize <= 0) {
1769 errorCode = XML_ERROR_NO_MEMORY;
1770 return NULL;
1771 }
1723 newBuf = (char *)MALLOC(bufferSize); 1772 newBuf = (char *)MALLOC(bufferSize);
1724 if (newBuf == 0) { 1773 if (newBuf == 0) {
1725 errorCode = XML_ERROR_NO_MEMORY; 1774 errorCode = XML_ERROR_NO_MEMORY;
1726 return NULL; 1775 return NULL;
1727 } 1776 }
1728 bufferLim = newBuf + bufferSize; 1777 bufferLim = newBuf + bufferSize;
1729 #ifdef XML_CONTEXT_BYTES 1778 #ifdef XML_CONTEXT_BYTES
1730 if (bufferPtr) { 1779 if (bufferPtr) {
1731 int keep = (int)(bufferPtr - buffer); 1780 int keep = (int)(bufferPtr - buffer);
1732 if (keep > XML_CONTEXT_BYTES) 1781 if (keep > XML_CONTEXT_BYTES)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 enum XML_Error XMLCALL 1883 enum XML_Error XMLCALL
1835 XML_GetErrorCode(XML_Parser parser) 1884 XML_GetErrorCode(XML_Parser parser)
1836 { 1885 {
1837 return errorCode; 1886 return errorCode;
1838 } 1887 }
1839 1888
1840 XML_Index XMLCALL 1889 XML_Index XMLCALL
1841 XML_GetCurrentByteIndex(XML_Parser parser) 1890 XML_GetCurrentByteIndex(XML_Parser parser)
1842 { 1891 {
1843 if (eventPtr) 1892 if (eventPtr)
1844 return parseEndByteIndex - (parseEndPtr - eventPtr); 1893 return (XML_Index)(parseEndByteIndex - (parseEndPtr - eventPtr));
1845 return -1; 1894 return -1;
1846 } 1895 }
1847 1896
1848 int XMLCALL 1897 int XMLCALL
1849 XML_GetCurrentByteCount(XML_Parser parser) 1898 XML_GetCurrentByteCount(XML_Parser parser)
1850 { 1899 {
1851 if (eventEndPtr && eventPtr) 1900 if (eventEndPtr && eventPtr)
1852 return (int)(eventEndPtr - eventPtr); 1901 return (int)(eventEndPtr - eventPtr);
1853 return 0; 1902 return 0;
1854 } 1903 }
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2408 tag->rawName = s + enc->minBytesPerChar; 2457 tag->rawName = s + enc->minBytesPerChar;
2409 tag->rawNameLength = XmlNameLength(enc, tag->rawName); 2458 tag->rawNameLength = XmlNameLength(enc, tag->rawName);
2410 ++tagLevel; 2459 ++tagLevel;
2411 { 2460 {
2412 const char *rawNameEnd = tag->rawName + tag->rawNameLength; 2461 const char *rawNameEnd = tag->rawName + tag->rawNameLength;
2413 const char *fromPtr = tag->rawName; 2462 const char *fromPtr = tag->rawName;
2414 toPtr = (XML_Char *)tag->buf; 2463 toPtr = (XML_Char *)tag->buf;
2415 for (;;) { 2464 for (;;) {
2416 int bufSize; 2465 int bufSize;
2417 int convLen; 2466 int convLen;
2418 XmlConvert(enc, 2467 const enum XML_Convert_Result convert_res = XmlConvert(enc,
2419 &fromPtr, rawNameEnd, 2468 &fromPtr, rawNameEnd,
2420 (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); 2469 (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);
2421 convLen = (int)(toPtr - (XML_Char *)tag->buf); 2470 convLen = (int)(toPtr - (XML_Char *)tag->buf);
2422 if (fromPtr == rawNameEnd) { 2471 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CO NVERT_INPUT_INCOMPLETE)) {
2423 tag->name.strLen = convLen; 2472 tag->name.strLen = convLen;
2424 break; 2473 break;
2425 } 2474 }
2426 bufSize = (int)(tag->bufEnd - tag->buf) << 1; 2475 bufSize = (int)(tag->bufEnd - tag->buf) << 1;
2427 { 2476 {
2428 char *temp = (char *)REALLOC(tag->buf, bufSize); 2477 char *temp = (char *)REALLOC(tag->buf, bufSize);
2429 if (temp == NULL) 2478 if (temp == NULL)
2430 return XML_ERROR_NO_MEMORY; 2479 return XML_ERROR_NO_MEMORY;
2431 tag->buf = temp; 2480 tag->buf = temp;
2432 tag->bufEnd = temp + bufSize; 2481 tag->bufEnd = temp + bufSize;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 } 2682 }
2634 *nextPtr = end; 2683 *nextPtr = end;
2635 return XML_ERROR_NONE; 2684 return XML_ERROR_NONE;
2636 case XML_TOK_DATA_CHARS: 2685 case XML_TOK_DATA_CHARS:
2637 { 2686 {
2638 XML_CharacterDataHandler charDataHandler = characterDataHandler; 2687 XML_CharacterDataHandler charDataHandler = characterDataHandler;
2639 if (charDataHandler) { 2688 if (charDataHandler) {
2640 if (MUST_CONVERT(enc, s)) { 2689 if (MUST_CONVERT(enc, s)) {
2641 for (;;) { 2690 for (;;) {
2642 ICHAR *dataPtr = (ICHAR *)dataBuf; 2691 ICHAR *dataPtr = (ICHAR *)dataBuf;
2643 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 2692 const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, ne xt, &dataPtr, (ICHAR *)dataBufEnd);
2644 *eventEndPP = s; 2693 *eventEndPP = s;
2645 charDataHandler(handlerArg, dataBuf, 2694 charDataHandler(handlerArg, dataBuf,
2646 (int)(dataPtr - (ICHAR *)dataBuf)); 2695 (int)(dataPtr - (ICHAR *)dataBuf));
2647 if (s == next) 2696 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_ CONVERT_INPUT_INCOMPLETE))
2648 break; 2697 break;
2649 *eventPP = s; 2698 *eventPP = s;
2650 } 2699 }
2651 } 2700 }
2652 else 2701 else
2653 charDataHandler(handlerArg, 2702 charDataHandler(handlerArg,
2654 (XML_Char *)s, 2703 (XML_Char *)s,
2655 (int)((XML_Char *)next - (XML_Char *)s)); 2704 (int)((XML_Char *)next - (XML_Char *)s));
2656 } 2705 }
2657 else if (defaultHandler) 2706 else if (defaultHandler)
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 2953
2905 /* expand prefixed names and check for duplicates */ 2954 /* expand prefixed names and check for duplicates */
2906 for (; i < attIndex; i += 2) { 2955 for (; i < attIndex; i += 2) {
2907 const XML_Char *s = appAtts[i]; 2956 const XML_Char *s = appAtts[i];
2908 if (s[-1] == 2) { /* prefixed */ 2957 if (s[-1] == 2) { /* prefixed */
2909 ATTRIBUTE_ID *id; 2958 ATTRIBUTE_ID *id;
2910 const BINDING *b; 2959 const BINDING *b;
2911 unsigned long uriHash = hash_secret_salt; 2960 unsigned long uriHash = hash_secret_salt;
2912 ((XML_Char *)s)[-1] = 0; /* clear flag */ 2961 ((XML_Char *)s)[-1] = 0; /* clear flag */
2913 id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0); 2962 id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0);
2963 if (!id || !id->prefix)
2964 return XML_ERROR_NO_MEMORY;
2914 b = id->prefix->binding; 2965 b = id->prefix->binding;
2915 if (!b) 2966 if (!b)
2916 return XML_ERROR_UNBOUND_PREFIX; 2967 return XML_ERROR_UNBOUND_PREFIX;
2917 2968
2918 /* as we expand the name we also calculate its hash value */ 2969 /* as we expand the name we also calculate its hash value */
2919 for (j = 0; j < b->uriLen; j++) { 2970 for (j = 0; j < b->uriLen; j++) {
2920 const XML_Char c = b->uri[j]; 2971 const XML_Char c = b->uri[j];
2921 if (!poolAppendChar(&tempPool, c)) 2972 if (!poolAppendChar(&tempPool, c))
2922 return XML_ERROR_NO_MEMORY; 2973 return XML_ERROR_NO_MEMORY;
2923 uriHash = CHAR_HASH(uriHash, c); 2974 uriHash = CHAR_HASH(uriHash, c);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 else if (defaultHandler) 3292 else if (defaultHandler)
3242 reportDefault(parser, enc, s, next); 3293 reportDefault(parser, enc, s, next);
3243 break; 3294 break;
3244 case XML_TOK_DATA_CHARS: 3295 case XML_TOK_DATA_CHARS:
3245 { 3296 {
3246 XML_CharacterDataHandler charDataHandler = characterDataHandler; 3297 XML_CharacterDataHandler charDataHandler = characterDataHandler;
3247 if (charDataHandler) { 3298 if (charDataHandler) {
3248 if (MUST_CONVERT(enc, s)) { 3299 if (MUST_CONVERT(enc, s)) {
3249 for (;;) { 3300 for (;;) {
3250 ICHAR *dataPtr = (ICHAR *)dataBuf; 3301 ICHAR *dataPtr = (ICHAR *)dataBuf;
3251 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 3302 const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, ne xt, &dataPtr, (ICHAR *)dataBufEnd);
3252 *eventEndPP = next; 3303 *eventEndPP = next;
3253 charDataHandler(handlerArg, dataBuf, 3304 charDataHandler(handlerArg, dataBuf,
3254 (int)(dataPtr - (ICHAR *)dataBuf)); 3305 (int)(dataPtr - (ICHAR *)dataBuf));
3255 if (s == next) 3306 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_ CONVERT_INPUT_INCOMPLETE))
3256 break; 3307 break;
3257 *eventPP = s; 3308 *eventPP = s;
3258 } 3309 }
3259 } 3310 }
3260 else 3311 else
3261 charDataHandler(handlerArg, 3312 charDataHandler(handlerArg,
3262 (XML_Char *)s, 3313 (XML_Char *)s,
3263 (int)((XML_Char *)next - (XML_Char *)s)); 3314 (int)((XML_Char *)next - (XML_Char *)s));
3264 } 3315 }
3265 else if (defaultHandler) 3316 else if (defaultHandler)
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
4904 { 4955 {
4905 processor = contentProcessor; 4956 processor = contentProcessor;
4906 /* see externalEntityContentProcessor vs contentProcessor */ 4957 /* see externalEntityContentProcessor vs contentProcessor */
4907 return doContent(parser, parentParser ? 1 : 0, encoding, s, end, 4958 return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
4908 nextPtr, (XML_Bool)!ps_finalBuffer); 4959 nextPtr, (XML_Bool)!ps_finalBuffer);
4909 } 4960 }
4910 } 4961 }
4911 4962
4912 static enum XML_Error PTRCALL 4963 static enum XML_Error PTRCALL
4913 errorProcessor(XML_Parser parser, 4964 errorProcessor(XML_Parser parser,
4914 const char *s, 4965 const char *UNUSED_P(s),
4915 const char *end, 4966 const char *UNUSED_P(end),
4916 const char **nextPtr) 4967 const char **UNUSED_P(nextPtr))
4917 { 4968 {
4918 return errorCode; 4969 return errorCode;
4919 } 4970 }
4920 4971
4921 static enum XML_Error 4972 static enum XML_Error
4922 storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, 4973 storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
4923 const char *ptr, const char *end, 4974 const char *ptr, const char *end,
4924 STRING_POOL *pool) 4975 STRING_POOL *pool)
4925 { 4976 {
4926 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, 4977 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr,
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
5322 commentHandler(handlerArg, data); 5373 commentHandler(handlerArg, data);
5323 poolClear(&tempPool); 5374 poolClear(&tempPool);
5324 return 1; 5375 return 1;
5325 } 5376 }
5326 5377
5327 static void 5378 static void
5328 reportDefault(XML_Parser parser, const ENCODING *enc, 5379 reportDefault(XML_Parser parser, const ENCODING *enc,
5329 const char *s, const char *end) 5380 const char *s, const char *end)
5330 { 5381 {
5331 if (MUST_CONVERT(enc, s)) { 5382 if (MUST_CONVERT(enc, s)) {
5383 enum XML_Convert_Result convert_res;
5332 const char **eventPP; 5384 const char **eventPP;
5333 const char **eventEndPP; 5385 const char **eventEndPP;
5334 if (enc == encoding) { 5386 if (enc == encoding) {
5335 eventPP = &eventPtr; 5387 eventPP = &eventPtr;
5336 eventEndPP = &eventEndPtr; 5388 eventEndPP = &eventEndPtr;
5337 } 5389 }
5338 else { 5390 else {
5339 eventPP = &(openInternalEntities->internalEventPtr); 5391 eventPP = &(openInternalEntities->internalEventPtr);
5340 eventEndPP = &(openInternalEntities->internalEventEndPtr); 5392 eventEndPP = &(openInternalEntities->internalEventEndPtr);
5341 } 5393 }
5342 do { 5394 do {
5343 ICHAR *dataPtr = (ICHAR *)dataBuf; 5395 ICHAR *dataPtr = (ICHAR *)dataBuf;
5344 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); 5396 convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
5345 *eventEndPP = s; 5397 *eventEndPP = s;
5346 defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); 5398 defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf));
5347 *eventPP = s; 5399 *eventPP = s;
5348 } while (s != end); 5400 } while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVE RT_INPUT_INCOMPLETE));
5349 } 5401 }
5350 else 5402 else
5351 defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); 5403 defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
5352 } 5404 }
5353 5405
5354 5406
5355 static int 5407 static int
5356 defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, 5408 defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
5357 XML_Bool isId, const XML_Char *value, XML_Parser parser) 5409 XML_Bool isId, const XML_Char *value, XML_Parser parser)
5358 { 5410 {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
5468 if (name[i] == XML_T(ASCII_COLON)) { 5520 if (name[i] == XML_T(ASCII_COLON)) {
5469 int j; 5521 int j;
5470 for (j = 0; j < i; j++) { 5522 for (j = 0; j < i; j++) {
5471 if (!poolAppendChar(&dtd->pool, name[j])) 5523 if (!poolAppendChar(&dtd->pool, name[j]))
5472 return NULL; 5524 return NULL;
5473 } 5525 }
5474 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) 5526 if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5475 return NULL; 5527 return NULL;
5476 id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd-> pool), 5528 id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd-> pool),
5477 sizeof(PREFIX)); 5529 sizeof(PREFIX));
5530 if (!id->prefix)
5531 return NULL;
5478 if (id->prefix->name == poolStart(&dtd->pool)) 5532 if (id->prefix->name == poolStart(&dtd->pool))
5479 poolFinish(&dtd->pool); 5533 poolFinish(&dtd->pool);
5480 else 5534 else
5481 poolDiscard(&dtd->pool); 5535 poolDiscard(&dtd->pool);
5482 break; 5536 break;
5483 } 5537 }
5484 } 5538 }
5485 } 5539 }
5486 } 5540 }
5487 return id; 5541 return id;
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
6141 } 6195 }
6142 } 6196 }
6143 6197
6144 static XML_Char * 6198 static XML_Char *
6145 poolAppend(STRING_POOL *pool, const ENCODING *enc, 6199 poolAppend(STRING_POOL *pool, const ENCODING *enc,
6146 const char *ptr, const char *end) 6200 const char *ptr, const char *end)
6147 { 6201 {
6148 if (!pool->ptr && !poolGrow(pool)) 6202 if (!pool->ptr && !poolGrow(pool))
6149 return NULL; 6203 return NULL;
6150 for (;;) { 6204 for (;;) {
6151 XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); 6205 const enum XML_Convert_Result convert_res = XmlConvert(enc, &ptr, end, (ICHA R **)&(pool->ptr), (ICHAR *)pool->end);
6152 if (ptr == end) 6206 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_IN PUT_INCOMPLETE))
6153 break; 6207 break;
6154 if (!poolGrow(pool)) 6208 if (!poolGrow(pool))
6155 return NULL; 6209 return NULL;
6156 } 6210 }
6157 return pool->start; 6211 return pool->start;
6158 } 6212 }
6159 6213
6160 static const XML_Char * FASTCALL 6214 static const XML_Char * FASTCALL
6161 poolCopyString(STRING_POOL *pool, const XML_Char *s) 6215 poolCopyString(STRING_POOL *pool, const XML_Char *s)
6162 { 6216 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
6226 pool->freeBlocks = tem; 6280 pool->freeBlocks = tem;
6227 memcpy(pool->blocks->s, pool->start, 6281 memcpy(pool->blocks->s, pool->start,
6228 (pool->end - pool->start) * sizeof(XML_Char)); 6282 (pool->end - pool->start) * sizeof(XML_Char));
6229 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6283 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6230 pool->start = pool->blocks->s; 6284 pool->start = pool->blocks->s;
6231 pool->end = pool->start + pool->blocks->size; 6285 pool->end = pool->start + pool->blocks->size;
6232 return XML_TRUE; 6286 return XML_TRUE;
6233 } 6287 }
6234 } 6288 }
6235 if (pool->blocks && pool->start == pool->blocks->s) { 6289 if (pool->blocks && pool->start == pool->blocks->s) {
6236 int blockSize = (int)(pool->end - pool->start)*2; 6290 BLOCK *temp;
6237 BLOCK *temp = (BLOCK *) 6291 int blockSize = (int)((unsigned)(pool->end - pool->start)*2U);
6292
6293 if (blockSize < 0)
6294 return XML_FALSE;
6295
6296 temp = (BLOCK *)
6238 pool->mem->realloc_fcn(pool->blocks, 6297 pool->mem->realloc_fcn(pool->blocks,
6239 (offsetof(BLOCK, s) 6298 (offsetof(BLOCK, s)
6240 + blockSize * sizeof(XML_Char))); 6299 + blockSize * sizeof(XML_Char)));
6241 if (temp == NULL) 6300 if (temp == NULL)
6242 return XML_FALSE; 6301 return XML_FALSE;
6243 pool->blocks = temp; 6302 pool->blocks = temp;
6244 pool->blocks->size = blockSize; 6303 pool->blocks->size = blockSize;
6245 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6304 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6246 pool->start = pool->blocks->s; 6305 pool->start = pool->blocks->s;
6247 pool->end = pool->start + blockSize; 6306 pool->end = pool->start + blockSize;
6248 } 6307 }
6249 else { 6308 else {
6250 BLOCK *tem; 6309 BLOCK *tem;
6251 int blockSize = (int)(pool->end - pool->start); 6310 int blockSize = (int)(pool->end - pool->start);
6311
6312 if (blockSize < 0)
6313 return XML_FALSE;
6314
6252 if (blockSize < INIT_BLOCK_SIZE) 6315 if (blockSize < INIT_BLOCK_SIZE)
6253 blockSize = INIT_BLOCK_SIZE; 6316 blockSize = INIT_BLOCK_SIZE;
6254 else 6317 else
6255 blockSize *= 2; 6318 blockSize *= 2;
6256 tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) 6319 tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s)
6257 + blockSize * sizeof(XML_Char)); 6320 + blockSize * sizeof(XML_Char));
6258 if (!tem) 6321 if (!tem)
6259 return XML_FALSE; 6322 return XML_FALSE;
6260 tem->size = blockSize; 6323 tem->size = blockSize;
6261 tem->next = pool->blocks; 6324 tem->next = pool->blocks;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
6394 return NULL; 6457 return NULL;
6395 if (ret->name != name) 6458 if (ret->name != name)
6396 poolDiscard(&dtd->pool); 6459 poolDiscard(&dtd->pool);
6397 else { 6460 else {
6398 poolFinish(&dtd->pool); 6461 poolFinish(&dtd->pool);
6399 if (!setElementTypePrefix(parser, ret)) 6462 if (!setElementTypePrefix(parser, ret))
6400 return NULL; 6463 return NULL;
6401 } 6464 }
6402 return ret; 6465 return ret;
6403 } 6466 }
OLDNEW
« no previous file with comments | « third_party/expat/files/lib/xmlparse.c ('k') | third_party/expat/files/lib/xmlrole.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698