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

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

Issue 2761253002: Update expat to 2.2.0 to fix CVE vulnerability. (Closed)
Patch Set: 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
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 (void)gettimeofday_res;
714
715 /* Microseconds time is <20 bits entropy */
716 return tv.tv_usec;
717 #endif
718 }
719
720 static unsigned long
721 generate_hash_secret_salt(XML_Parser parser)
722 {
723 /* Process ID is 0 bits entropy if attacker has local access
724 * XML_Parser address is few bits of entropy if attacker has local access */
725 const unsigned long entropy =
726 gather_time_entropy() ^ getpid() ^ (unsigned long)parser;
727
728 /* Factors are 2^31-1 and 2^61-1 (Mersenne primes M31 and M61) */
729 if (sizeof(unsigned long) == 4) {
730 return entropy * 2147483647;
731 } else {
732 return entropy * (unsigned long)2305843009213693951;
733 }
699 } 734 }
700 735
701 static XML_Bool /* only valid for root parser */ 736 static XML_Bool /* only valid for root parser */
702 startParsing(XML_Parser parser) 737 startParsing(XML_Parser parser)
703 { 738 {
704 /* hash functions must be initialized before setContext() is called */ 739 /* hash functions must be initialized before setContext() is called */
705 if (hash_secret_salt == 0) 740 if (hash_secret_salt == 0)
706 hash_secret_salt = generate_hash_secret_salt(); 741 hash_secret_salt = generate_hash_secret_salt(parser);
707 if (ns) { 742 if (ns) {
708 /* implicit context only set for root parser, since child 743 /* implicit context only set for root parser, since child
709 parsers (i.e. external entity parsers) will inherit it 744 parsers (i.e. external entity parsers) will inherit it
710 */ 745 */
711 return setContext(parser, implicitContext); 746 return setContext(parser, implicitContext);
712 } 747 }
713 return XML_TRUE; 748 return XML_TRUE;
714 } 749 }
715 750
716 XML_Parser XMLCALL 751 XML_Parser XMLCALL
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 } 1578 }
1544 } 1579 }
1545 eventEndPtr = eventPtr; 1580 eventEndPtr = eventPtr;
1546 processor = errorProcessor; 1581 processor = errorProcessor;
1547 return XML_STATUS_ERROR; 1582 return XML_STATUS_ERROR;
1548 } 1583 }
1549 #ifndef XML_CONTEXT_BYTES 1584 #ifndef XML_CONTEXT_BYTES
1550 else if (bufferPtr == bufferEnd) { 1585 else if (bufferPtr == bufferEnd) {
1551 const char *end; 1586 const char *end;
1552 int nLeftOver; 1587 int nLeftOver;
1553 enum XML_Error result; 1588 enum XML_Status result;
1554 parseEndByteIndex += len; 1589 parseEndByteIndex += len;
1555 positionPtr = s; 1590 positionPtr = s;
1556 ps_finalBuffer = (XML_Bool)isFinal; 1591 ps_finalBuffer = (XML_Bool)isFinal;
1557 1592
1558 errorCode = processor(parser, s, parseEndPtr = s + len, &end); 1593 errorCode = processor(parser, s, parseEndPtr = s + len, &end);
1559 1594
1560 if (errorCode != XML_ERROR_NONE) { 1595 if (errorCode != XML_ERROR_NONE) {
1561 eventEndPtr = eventPtr; 1596 eventEndPtr = eventPtr;
1562 processor = errorProcessor; 1597 processor = errorProcessor;
1563 return XML_STATUS_ERROR; 1598 return XML_STATUS_ERROR;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 } 1706 }
1672 1707
1673 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); 1708 XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
1674 positionPtr = bufferPtr; 1709 positionPtr = bufferPtr;
1675 return result; 1710 return result;
1676 } 1711 }
1677 1712
1678 void * XMLCALL 1713 void * XMLCALL
1679 XML_GetBuffer(XML_Parser parser, int len) 1714 XML_GetBuffer(XML_Parser parser, int len)
1680 { 1715 {
1681 /* BEGIN MOZILLA CHANGE (sanity check len) */
1682 if (len < 0) { 1716 if (len < 0) {
1683 errorCode = XML_ERROR_NO_MEMORY; 1717 errorCode = XML_ERROR_NO_MEMORY;
1684 return NULL; 1718 return NULL;
1685 } 1719 }
1686 /* END MOZILLA CHANGE */
1687 switch (ps_parsing) { 1720 switch (ps_parsing) {
1688 case XML_SUSPENDED: 1721 case XML_SUSPENDED:
1689 errorCode = XML_ERROR_SUSPENDED; 1722 errorCode = XML_ERROR_SUSPENDED;
1690 return NULL; 1723 return NULL;
1691 case XML_FINISHED: 1724 case XML_FINISHED:
1692 errorCode = XML_ERROR_FINISHED; 1725 errorCode = XML_ERROR_FINISHED;
1693 return NULL; 1726 return NULL;
1694 default: ; 1727 default: ;
1695 } 1728 }
1696 1729
1697 if (len > bufferLim - bufferEnd) { 1730 if (len > bufferLim - bufferEnd) {
1698 int neededSize = len + (int)(bufferEnd - bufferPtr); 1731 #ifdef XML_CONTEXT_BYTES
1699 /* BEGIN MOZILLA CHANGE (sanity check neededSize) */ 1732 int keep;
1733 #endif /* defined XML_CONTEXT_BYTES */
1734 /* Do not invoke signed arithmetic overflow: */
1735 int neededSize = (int) ((unsigned)len + (unsigned)(bufferEnd - bufferPtr));
1700 if (neededSize < 0) { 1736 if (neededSize < 0) {
1701 errorCode = XML_ERROR_NO_MEMORY; 1737 errorCode = XML_ERROR_NO_MEMORY;
1702 return NULL; 1738 return NULL;
1703 } 1739 }
1704 /* END MOZILLA CHANGE */
1705 #ifdef XML_CONTEXT_BYTES 1740 #ifdef XML_CONTEXT_BYTES
1706 int keep = (int)(bufferPtr - buffer); 1741 keep = (int)(bufferPtr - buffer);
1707
1708 if (keep > XML_CONTEXT_BYTES) 1742 if (keep > XML_CONTEXT_BYTES)
1709 keep = XML_CONTEXT_BYTES; 1743 keep = XML_CONTEXT_BYTES;
1710 neededSize += keep; 1744 neededSize += keep;
1711 #endif /* defined XML_CONTEXT_BYTES */ 1745 #endif /* defined XML_CONTEXT_BYTES */
1712 if (neededSize <= bufferLim - buffer) { 1746 if (neededSize <= bufferLim - buffer) {
1713 #ifdef XML_CONTEXT_BYTES 1747 #ifdef XML_CONTEXT_BYTES
1714 if (keep < bufferPtr - buffer) { 1748 if (keep < bufferPtr - buffer) {
1715 int offset = (int)(bufferPtr - buffer) - keep; 1749 int offset = (int)(bufferPtr - buffer) - keep;
1716 memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); 1750 memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);
1717 bufferEnd -= offset; 1751 bufferEnd -= offset;
1718 bufferPtr -= offset; 1752 bufferPtr -= offset;
1719 } 1753 }
1720 #else 1754 #else
1721 memmove(buffer, bufferPtr, bufferEnd - bufferPtr); 1755 memmove(buffer, bufferPtr, bufferEnd - bufferPtr);
1722 bufferEnd = buffer + (bufferEnd - bufferPtr); 1756 bufferEnd = buffer + (bufferEnd - bufferPtr);
1723 bufferPtr = buffer; 1757 bufferPtr = buffer;
1724 #endif /* not defined XML_CONTEXT_BYTES */ 1758 #endif /* not defined XML_CONTEXT_BYTES */
1725 } 1759 }
1726 else { 1760 else {
1727 char *newBuf; 1761 char *newBuf;
1728 int bufferSize = (int)(bufferLim - bufferPtr); 1762 int bufferSize = (int)(bufferLim - bufferPtr);
1729 if (bufferSize == 0) 1763 if (bufferSize == 0)
1730 bufferSize = INIT_BUFFER_SIZE; 1764 bufferSize = INIT_BUFFER_SIZE;
1731 do { 1765 do {
1732 bufferSize *= 2; 1766 /* Do not invoke signed arithmetic overflow: */
1733 /* BEGIN MOZILLA CHANGE (prevent infinite loop on overflow) */ 1767 bufferSize = (int) (2U * (unsigned) bufferSize);
1734 } while (bufferSize < neededSize && bufferSize > 0); 1768 } while (bufferSize < neededSize && bufferSize > 0);
1735 /* END MOZILLA CHANGE */
1736 /* BEGIN MOZILLA CHANGE (sanity check bufferSize) */
1737 if (bufferSize <= 0) { 1769 if (bufferSize <= 0) {
1738 errorCode = XML_ERROR_NO_MEMORY; 1770 errorCode = XML_ERROR_NO_MEMORY;
1739 return NULL; 1771 return NULL;
1740 } 1772 }
1741 /* END MOZILLA CHANGE */
1742 newBuf = (char *)MALLOC(bufferSize); 1773 newBuf = (char *)MALLOC(bufferSize);
1743 if (newBuf == 0) { 1774 if (newBuf == 0) {
1744 errorCode = XML_ERROR_NO_MEMORY; 1775 errorCode = XML_ERROR_NO_MEMORY;
1745 return NULL; 1776 return NULL;
1746 } 1777 }
1747 bufferLim = newBuf + bufferSize; 1778 bufferLim = newBuf + bufferSize;
1748 #ifdef XML_CONTEXT_BYTES 1779 #ifdef XML_CONTEXT_BYTES
1749 if (bufferPtr) { 1780 if (bufferPtr) {
1750 int keep = (int)(bufferPtr - buffer); 1781 int keep = (int)(bufferPtr - buffer);
1751 if (keep > XML_CONTEXT_BYTES) 1782 if (keep > XML_CONTEXT_BYTES)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 enum XML_Error XMLCALL 1884 enum XML_Error XMLCALL
1854 XML_GetErrorCode(XML_Parser parser) 1885 XML_GetErrorCode(XML_Parser parser)
1855 { 1886 {
1856 return errorCode; 1887 return errorCode;
1857 } 1888 }
1858 1889
1859 XML_Index XMLCALL 1890 XML_Index XMLCALL
1860 XML_GetCurrentByteIndex(XML_Parser parser) 1891 XML_GetCurrentByteIndex(XML_Parser parser)
1861 { 1892 {
1862 if (eventPtr) 1893 if (eventPtr)
1863 return parseEndByteIndex - (parseEndPtr - eventPtr); 1894 return (XML_Index)(parseEndByteIndex - (parseEndPtr - eventPtr));
1864 return -1; 1895 return -1;
1865 } 1896 }
1866 1897
1867 int XMLCALL 1898 int XMLCALL
1868 XML_GetCurrentByteCount(XML_Parser parser) 1899 XML_GetCurrentByteCount(XML_Parser parser)
1869 { 1900 {
1870 if (eventEndPtr && eventPtr) 1901 if (eventEndPtr && eventPtr)
1871 return (int)(eventEndPtr - eventPtr); 1902 return (int)(eventEndPtr - eventPtr);
1872 return 0; 1903 return 0;
1873 } 1904 }
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 tag->rawName = s + enc->minBytesPerChar; 2458 tag->rawName = s + enc->minBytesPerChar;
2428 tag->rawNameLength = XmlNameLength(enc, tag->rawName); 2459 tag->rawNameLength = XmlNameLength(enc, tag->rawName);
2429 ++tagLevel; 2460 ++tagLevel;
2430 { 2461 {
2431 const char *rawNameEnd = tag->rawName + tag->rawNameLength; 2462 const char *rawNameEnd = tag->rawName + tag->rawNameLength;
2432 const char *fromPtr = tag->rawName; 2463 const char *fromPtr = tag->rawName;
2433 toPtr = (XML_Char *)tag->buf; 2464 toPtr = (XML_Char *)tag->buf;
2434 for (;;) { 2465 for (;;) {
2435 int bufSize; 2466 int bufSize;
2436 int convLen; 2467 int convLen;
2437 XmlConvert(enc, 2468 const enum XML_Convert_Result convert_res = XmlConvert(enc,
2438 &fromPtr, rawNameEnd, 2469 &fromPtr, rawNameEnd,
2439 (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); 2470 (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);
2440 convLen = (int)(toPtr - (XML_Char *)tag->buf); 2471 convLen = (int)(toPtr - (XML_Char *)tag->buf);
2441 if (fromPtr == rawNameEnd) { 2472 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CO NVERT_INPUT_INCOMPLETE)) {
2442 tag->name.strLen = convLen; 2473 tag->name.strLen = convLen;
2443 break; 2474 break;
2444 } 2475 }
2445 bufSize = (int)(tag->bufEnd - tag->buf) << 1; 2476 bufSize = (int)(tag->bufEnd - tag->buf) << 1;
2446 { 2477 {
2447 char *temp = (char *)REALLOC(tag->buf, bufSize); 2478 char *temp = (char *)REALLOC(tag->buf, bufSize);
2448 if (temp == NULL) 2479 if (temp == NULL)
2449 return XML_ERROR_NO_MEMORY; 2480 return XML_ERROR_NO_MEMORY;
2450 tag->buf = temp; 2481 tag->buf = temp;
2451 tag->bufEnd = temp + bufSize; 2482 tag->bufEnd = temp + bufSize;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2652 } 2683 }
2653 *nextPtr = end; 2684 *nextPtr = end;
2654 return XML_ERROR_NONE; 2685 return XML_ERROR_NONE;
2655 case XML_TOK_DATA_CHARS: 2686 case XML_TOK_DATA_CHARS:
2656 { 2687 {
2657 XML_CharacterDataHandler charDataHandler = characterDataHandler; 2688 XML_CharacterDataHandler charDataHandler = characterDataHandler;
2658 if (charDataHandler) { 2689 if (charDataHandler) {
2659 if (MUST_CONVERT(enc, s)) { 2690 if (MUST_CONVERT(enc, s)) {
2660 for (;;) { 2691 for (;;) {
2661 ICHAR *dataPtr = (ICHAR *)dataBuf; 2692 ICHAR *dataPtr = (ICHAR *)dataBuf;
2662 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 2693 const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, ne xt, &dataPtr, (ICHAR *)dataBufEnd);
2663 *eventEndPP = s; 2694 *eventEndPP = s;
2664 charDataHandler(handlerArg, dataBuf, 2695 charDataHandler(handlerArg, dataBuf,
2665 (int)(dataPtr - (ICHAR *)dataBuf)); 2696 (int)(dataPtr - (ICHAR *)dataBuf));
2666 if (s == next) 2697 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_ CONVERT_INPUT_INCOMPLETE))
2667 break; 2698 break;
2668 *eventPP = s; 2699 *eventPP = s;
2669 } 2700 }
2670 } 2701 }
2671 else 2702 else
2672 charDataHandler(handlerArg, 2703 charDataHandler(handlerArg,
2673 (XML_Char *)s, 2704 (XML_Char *)s,
2674 (int)((XML_Char *)next - (XML_Char *)s)); 2705 (int)((XML_Char *)next - (XML_Char *)s));
2675 } 2706 }
2676 else if (defaultHandler) 2707 else if (defaultHandler)
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2923 2954
2924 /* expand prefixed names and check for duplicates */ 2955 /* expand prefixed names and check for duplicates */
2925 for (; i < attIndex; i += 2) { 2956 for (; i < attIndex; i += 2) {
2926 const XML_Char *s = appAtts[i]; 2957 const XML_Char *s = appAtts[i];
2927 if (s[-1] == 2) { /* prefixed */ 2958 if (s[-1] == 2) { /* prefixed */
2928 ATTRIBUTE_ID *id; 2959 ATTRIBUTE_ID *id;
2929 const BINDING *b; 2960 const BINDING *b;
2930 unsigned long uriHash = hash_secret_salt; 2961 unsigned long uriHash = hash_secret_salt;
2931 ((XML_Char *)s)[-1] = 0; /* clear flag */ 2962 ((XML_Char *)s)[-1] = 0; /* clear flag */
2932 id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0); 2963 id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0);
2964 if (!id || !id->prefix)
2965 return XML_ERROR_NO_MEMORY;
2933 b = id->prefix->binding; 2966 b = id->prefix->binding;
2934 if (!b) 2967 if (!b)
2935 return XML_ERROR_UNBOUND_PREFIX; 2968 return XML_ERROR_UNBOUND_PREFIX;
2936 2969
2937 /* as we expand the name we also calculate its hash value */ 2970 /* as we expand the name we also calculate its hash value */
2938 for (j = 0; j < b->uriLen; j++) { 2971 for (j = 0; j < b->uriLen; j++) {
2939 const XML_Char c = b->uri[j]; 2972 const XML_Char c = b->uri[j];
2940 if (!poolAppendChar(&tempPool, c)) 2973 if (!poolAppendChar(&tempPool, c))
2941 return XML_ERROR_NO_MEMORY; 2974 return XML_ERROR_NO_MEMORY;
2942 uriHash = CHAR_HASH(uriHash, c); 2975 uriHash = CHAR_HASH(uriHash, c);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3260 else if (defaultHandler) 3293 else if (defaultHandler)
3261 reportDefault(parser, enc, s, next); 3294 reportDefault(parser, enc, s, next);
3262 break; 3295 break;
3263 case XML_TOK_DATA_CHARS: 3296 case XML_TOK_DATA_CHARS:
3264 { 3297 {
3265 XML_CharacterDataHandler charDataHandler = characterDataHandler; 3298 XML_CharacterDataHandler charDataHandler = characterDataHandler;
3266 if (charDataHandler) { 3299 if (charDataHandler) {
3267 if (MUST_CONVERT(enc, s)) { 3300 if (MUST_CONVERT(enc, s)) {
3268 for (;;) { 3301 for (;;) {
3269 ICHAR *dataPtr = (ICHAR *)dataBuf; 3302 ICHAR *dataPtr = (ICHAR *)dataBuf;
3270 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); 3303 const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, ne xt, &dataPtr, (ICHAR *)dataBufEnd);
3271 *eventEndPP = next; 3304 *eventEndPP = next;
3272 charDataHandler(handlerArg, dataBuf, 3305 charDataHandler(handlerArg, dataBuf,
3273 (int)(dataPtr - (ICHAR *)dataBuf)); 3306 (int)(dataPtr - (ICHAR *)dataBuf));
3274 if (s == next) 3307 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_ CONVERT_INPUT_INCOMPLETE))
3275 break; 3308 break;
3276 *eventPP = s; 3309 *eventPP = s;
3277 } 3310 }
3278 } 3311 }
3279 else 3312 else
3280 charDataHandler(handlerArg, 3313 charDataHandler(handlerArg,
3281 (XML_Char *)s, 3314 (XML_Char *)s,
3282 (int)((XML_Char *)next - (XML_Char *)s)); 3315 (int)((XML_Char *)next - (XML_Char *)s));
3283 } 3316 }
3284 else if (defaultHandler) 3317 else if (defaultHandler)
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
4923 { 4956 {
4924 processor = contentProcessor; 4957 processor = contentProcessor;
4925 /* see externalEntityContentProcessor vs contentProcessor */ 4958 /* see externalEntityContentProcessor vs contentProcessor */
4926 return doContent(parser, parentParser ? 1 : 0, encoding, s, end, 4959 return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
4927 nextPtr, (XML_Bool)!ps_finalBuffer); 4960 nextPtr, (XML_Bool)!ps_finalBuffer);
4928 } 4961 }
4929 } 4962 }
4930 4963
4931 static enum XML_Error PTRCALL 4964 static enum XML_Error PTRCALL
4932 errorProcessor(XML_Parser parser, 4965 errorProcessor(XML_Parser parser,
4933 const char *s, 4966 const char *UNUSED_P(s),
4934 const char *end, 4967 const char *UNUSED_P(end),
4935 const char **nextPtr) 4968 const char **UNUSED_P(nextPtr))
4936 { 4969 {
4937 return errorCode; 4970 return errorCode;
4938 } 4971 }
4939 4972
4940 static enum XML_Error 4973 static enum XML_Error
4941 storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, 4974 storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
4942 const char *ptr, const char *end, 4975 const char *ptr, const char *end,
4943 STRING_POOL *pool) 4976 STRING_POOL *pool)
4944 { 4977 {
4945 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, 4978 enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr,
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
5341 commentHandler(handlerArg, data); 5374 commentHandler(handlerArg, data);
5342 poolClear(&tempPool); 5375 poolClear(&tempPool);
5343 return 1; 5376 return 1;
5344 } 5377 }
5345 5378
5346 static void 5379 static void
5347 reportDefault(XML_Parser parser, const ENCODING *enc, 5380 reportDefault(XML_Parser parser, const ENCODING *enc,
5348 const char *s, const char *end) 5381 const char *s, const char *end)
5349 { 5382 {
5350 if (MUST_CONVERT(enc, s)) { 5383 if (MUST_CONVERT(enc, s)) {
5384 enum XML_Convert_Result convert_res;
5351 const char **eventPP; 5385 const char **eventPP;
5352 const char **eventEndPP; 5386 const char **eventEndPP;
5353 if (enc == encoding) { 5387 if (enc == encoding) {
5354 eventPP = &eventPtr; 5388 eventPP = &eventPtr;
5355 eventEndPP = &eventEndPtr; 5389 eventEndPP = &eventEndPtr;
5356 } 5390 }
5357 else { 5391 else {
5358 eventPP = &(openInternalEntities->internalEventPtr); 5392 eventPP = &(openInternalEntities->internalEventPtr);
5359 eventEndPP = &(openInternalEntities->internalEventEndPtr); 5393 eventEndPP = &(openInternalEntities->internalEventEndPtr);
5360 } 5394 }
5361 do { 5395 do {
5362 ICHAR *dataPtr = (ICHAR *)dataBuf; 5396 ICHAR *dataPtr = (ICHAR *)dataBuf;
5363 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); 5397 convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
5364 *eventEndPP = s; 5398 *eventEndPP = s;
5365 defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); 5399 defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf));
5366 *eventPP = s; 5400 *eventPP = s;
5367 } while (s != end); 5401 } while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVE RT_INPUT_INCOMPLETE));
5368 } 5402 }
5369 else 5403 else
5370 defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); 5404 defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
5371 } 5405 }
5372 5406
5373 5407
5374 static int 5408 static int
5375 defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, 5409 defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
5376 XML_Bool isId, const XML_Char *value, XML_Parser parser) 5410 XML_Bool isId, const XML_Char *value, XML_Parser parser)
5377 { 5411 {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
5487 if (name[i] == XML_T(ASCII_COLON)) { 5521 if (name[i] == XML_T(ASCII_COLON)) {
5488 int j; 5522 int j;
5489 for (j = 0; j < i; j++) { 5523 for (j = 0; j < i; j++) {
5490 if (!poolAppendChar(&dtd->pool, name[j])) 5524 if (!poolAppendChar(&dtd->pool, name[j]))
5491 return NULL; 5525 return NULL;
5492 } 5526 }
5493 if (!poolAppendChar(&dtd->pool, XML_T('\0'))) 5527 if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5494 return NULL; 5528 return NULL;
5495 id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd-> pool), 5529 id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd-> pool),
5496 sizeof(PREFIX)); 5530 sizeof(PREFIX));
5531 if (!id->prefix)
5532 return NULL;
5497 if (id->prefix->name == poolStart(&dtd->pool)) 5533 if (id->prefix->name == poolStart(&dtd->pool))
5498 poolFinish(&dtd->pool); 5534 poolFinish(&dtd->pool);
5499 else 5535 else
5500 poolDiscard(&dtd->pool); 5536 poolDiscard(&dtd->pool);
5501 break; 5537 break;
5502 } 5538 }
5503 } 5539 }
5504 } 5540 }
5505 } 5541 }
5506 return id; 5542 return id;
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
6160 } 6196 }
6161 } 6197 }
6162 6198
6163 static XML_Char * 6199 static XML_Char *
6164 poolAppend(STRING_POOL *pool, const ENCODING *enc, 6200 poolAppend(STRING_POOL *pool, const ENCODING *enc,
6165 const char *ptr, const char *end) 6201 const char *ptr, const char *end)
6166 { 6202 {
6167 if (!pool->ptr && !poolGrow(pool)) 6203 if (!pool->ptr && !poolGrow(pool))
6168 return NULL; 6204 return NULL;
6169 for (;;) { 6205 for (;;) {
6170 XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); 6206 const enum XML_Convert_Result convert_res = XmlConvert(enc, &ptr, end, (ICHA R **)&(pool->ptr), (ICHAR *)pool->end);
6171 if (ptr == end) 6207 if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_IN PUT_INCOMPLETE))
6172 break; 6208 break;
6173 if (!poolGrow(pool)) 6209 if (!poolGrow(pool))
6174 return NULL; 6210 return NULL;
6175 } 6211 }
6176 return pool->start; 6212 return pool->start;
6177 } 6213 }
6178 6214
6179 static const XML_Char * FASTCALL 6215 static const XML_Char * FASTCALL
6180 poolCopyString(STRING_POOL *pool, const XML_Char *s) 6216 poolCopyString(STRING_POOL *pool, const XML_Char *s)
6181 { 6217 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
6245 pool->freeBlocks = tem; 6281 pool->freeBlocks = tem;
6246 memcpy(pool->blocks->s, pool->start, 6282 memcpy(pool->blocks->s, pool->start,
6247 (pool->end - pool->start) * sizeof(XML_Char)); 6283 (pool->end - pool->start) * sizeof(XML_Char));
6248 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6284 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6249 pool->start = pool->blocks->s; 6285 pool->start = pool->blocks->s;
6250 pool->end = pool->start + pool->blocks->size; 6286 pool->end = pool->start + pool->blocks->size;
6251 return XML_TRUE; 6287 return XML_TRUE;
6252 } 6288 }
6253 } 6289 }
6254 if (pool->blocks && pool->start == pool->blocks->s) { 6290 if (pool->blocks && pool->start == pool->blocks->s) {
6255 int blockSize = (int)(pool->end - pool->start)*2; 6291 BLOCK *temp;
6256 BLOCK *temp = (BLOCK *) 6292 int blockSize = (int)((unsigned)(pool->end - pool->start)*2U);
6293
6294 if (blockSize < 0)
6295 return XML_FALSE;
6296
6297 temp = (BLOCK *)
6257 pool->mem->realloc_fcn(pool->blocks, 6298 pool->mem->realloc_fcn(pool->blocks,
6258 (offsetof(BLOCK, s) 6299 (offsetof(BLOCK, s)
6259 + blockSize * sizeof(XML_Char))); 6300 + blockSize * sizeof(XML_Char)));
6260 if (temp == NULL) 6301 if (temp == NULL)
6261 return XML_FALSE; 6302 return XML_FALSE;
6262 pool->blocks = temp; 6303 pool->blocks = temp;
6263 pool->blocks->size = blockSize; 6304 pool->blocks->size = blockSize;
6264 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 6305 pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6265 pool->start = pool->blocks->s; 6306 pool->start = pool->blocks->s;
6266 pool->end = pool->start + blockSize; 6307 pool->end = pool->start + blockSize;
6267 } 6308 }
6268 else { 6309 else {
6269 BLOCK *tem; 6310 BLOCK *tem;
6270 int blockSize = (int)(pool->end - pool->start); 6311 int blockSize = (int)(pool->end - pool->start);
6312
6313 if (blockSize < 0)
6314 return XML_FALSE;
6315
6271 if (blockSize < INIT_BLOCK_SIZE) 6316 if (blockSize < INIT_BLOCK_SIZE)
6272 blockSize = INIT_BLOCK_SIZE; 6317 blockSize = INIT_BLOCK_SIZE;
6273 else 6318 else
6274 blockSize *= 2; 6319 blockSize *= 2;
6275 tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) 6320 tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s)
6276 + blockSize * sizeof(XML_Char)); 6321 + blockSize * sizeof(XML_Char));
6277 if (!tem) 6322 if (!tem)
6278 return XML_FALSE; 6323 return XML_FALSE;
6279 tem->size = blockSize; 6324 tem->size = blockSize;
6280 tem->next = pool->blocks; 6325 tem->next = pool->blocks;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
6413 return NULL; 6458 return NULL;
6414 if (ret->name != name) 6459 if (ret->name != name)
6415 poolDiscard(&dtd->pool); 6460 poolDiscard(&dtd->pool);
6416 else { 6461 else {
6417 poolFinish(&dtd->pool); 6462 poolFinish(&dtd->pool);
6418 if (!setElementTypePrefix(parser, ret)) 6463 if (!setElementTypePrefix(parser, ret))
6419 return NULL; 6464 return NULL;
6420 } 6465 }
6421 return ret; 6466 return ret;
6422 } 6467 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698