Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5033aa7

Browse files
authoredSep 11, 2018
bpo-34625: Update vendorized expat version to 2.2.6. (GH-9150)
1 parent 2064bb6 commit 5033aa7

File tree

5 files changed

+70
-27
lines changed

5 files changed

+70
-27
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update vendorized expat library version to 2.2.6.

‎Modules/expat/expat.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ XML_ParserCreate_MM(const XML_Char *encoding,
264264
const XML_Char *namespaceSeparator);
265265

266266
/* Prepare a parser object to be re-used. This is particularly
267-
valuable when memory allocation overhead is disproportionatly high,
267+
valuable when memory allocation overhead is disproportionately high,
268268
such as when a large number of small documnents need to be parsed.
269269
All handlers are cleared from the parser, except for the
270270
unknownEncodingHandler. The parser's external state is re-initialized
@@ -1076,7 +1076,7 @@ XML_GetFeatureList(void);
10761076
*/
10771077
#define XML_MAJOR_VERSION 2
10781078
#define XML_MINOR_VERSION 2
1079-
#define XML_MICRO_VERSION 5
1079+
#define XML_MICRO_VERSION 6
10801080

10811081
#ifdef __cplusplus
10821082
}

‎Modules/expat/siphash.h

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
* --------------------------------------------------------------------------
1212
* HISTORY:
1313
*
14+
* 2018-07-08 (Anton Maklakov)
15+
* - Add "fall through" markers for GCC's -Wimplicit-fallthrough
16+
*
17+
* 2017-11-03 (Sebastian Pipping)
18+
* - Hide sip_tobin and sip_binof unless SIPHASH_TOBIN macro is defined
19+
*
1420
* 2017-07-25 (Vadim Zeitlin)
1521
* - Fix use of SIPHASH_MAIN macro
1622
*
@@ -151,13 +157,17 @@ static struct sipkey *sip_tokey(struct sipkey *key, const void *src) {
151157
} /* sip_tokey() */
152158

153159

160+
#ifdef SIPHASH_TOBIN
161+
154162
#define sip_binof(v) sip_tobin((unsigned char[8]){ 0 }, (v))
155163

156164
static void *sip_tobin(void *dst, uint64_t u64) {
157165
SIP_U64TO8_LE((unsigned char *)dst, u64);
158166
return dst;
159167
} /* sip_tobin() */
160168

169+
#endif /* SIPHASH_TOBIN */
170+
161171

162172
static void sip_round(struct siphash *H, const int rounds) {
163173
int i;
@@ -231,12 +241,19 @@ static uint64_t sip24_final(struct siphash *H) {
231241

232242
switch (left) {
233243
case 7: b |= (uint64_t)H->buf[6] << 48;
244+
/* fall through */
234245
case 6: b |= (uint64_t)H->buf[5] << 40;
246+
/* fall through */
235247
case 5: b |= (uint64_t)H->buf[4] << 32;
248+
/* fall through */
236249
case 4: b |= (uint64_t)H->buf[3] << 24;
250+
/* fall through */
237251
case 3: b |= (uint64_t)H->buf[2] << 16;
252+
/* fall through */
238253
case 2: b |= (uint64_t)H->buf[1] << 8;
254+
/* fall through */
239255
case 1: b |= (uint64_t)H->buf[0] << 0;
256+
/* fall through */
240257
case 0: break;
241258
}
242259

‎Modules/expat/xmlparse.c

+44-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* 4b74aa710b4ed5ce464b0ce544852cb47bf905c85a49c7bae2749f5885cb966d (2.2.5+)
1+
/* 19ac4776051591216f1874e34ee99b6a43a3784c8bd7d70efeb9258dd22b906a (2.2.6+)
22
__ __ _
33
___\ \/ /_ __ __ _| |_
44
/ _ \\ /| '_ \ / _` | __|
@@ -161,6 +161,9 @@ typedef char ICHAR;
161161
/* Round up n to be a multiple of sz, where sz is a power of 2. */
162162
#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
163163

164+
/* Do safe (NULL-aware) pointer arithmetic */
165+
#define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0)
166+
164167
/* Handle the case where memmove() doesn't exist. */
165168
#ifndef HAVE_MEMMOVE
166169
#ifdef HAVE_BCOPY
@@ -1820,6 +1823,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
18201823
parser->m_errorCode = XML_ERROR_NO_MEMORY;
18211824
return XML_STATUS_ERROR;
18221825
}
1826+
/* fall through */
18231827
default:
18241828
parser->m_parsingStatus.parsing = XML_PARSING;
18251829
}
@@ -1969,6 +1973,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
19691973
parser->m_errorCode = XML_ERROR_NO_MEMORY;
19701974
return XML_STATUS_ERROR;
19711975
}
1976+
/* fall through */
19721977
default:
19731978
parser->m_parsingStatus.parsing = XML_PARSING;
19741979
}
@@ -2026,39 +2031,46 @@ XML_GetBuffer(XML_Parser parser, int len)
20262031
default: ;
20272032
}
20282033

2029-
if (len > parser->m_bufferLim - parser->m_bufferEnd) {
2034+
if (len > EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd)) {
20302035
#ifdef XML_CONTEXT_BYTES
20312036
int keep;
20322037
#endif /* defined XML_CONTEXT_BYTES */
20332038
/* Do not invoke signed arithmetic overflow: */
2034-
int neededSize = (int) ((unsigned)len + (unsigned)(parser->m_bufferEnd - parser->m_bufferPtr));
2039+
int neededSize = (int) ((unsigned)len +
2040+
(unsigned)EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd,
2041+
parser->m_bufferPtr));
20352042
if (neededSize < 0) {
20362043
parser->m_errorCode = XML_ERROR_NO_MEMORY;
20372044
return NULL;
20382045
}
20392046
#ifdef XML_CONTEXT_BYTES
2040-
keep = (int)(parser->m_bufferPtr - parser->m_buffer);
2047+
keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer);
20412048
if (keep > XML_CONTEXT_BYTES)
20422049
keep = XML_CONTEXT_BYTES;
20432050
neededSize += keep;
20442051
#endif /* defined XML_CONTEXT_BYTES */
2045-
if (neededSize <= parser->m_bufferLim - parser->m_buffer) {
2052+
if (neededSize <= EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer)) {
20462053
#ifdef XML_CONTEXT_BYTES
2047-
if (keep < parser->m_bufferPtr - parser->m_buffer) {
2048-
int offset = (int)(parser->m_bufferPtr - parser->m_buffer) - keep;
2054+
if (keep < EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer)) {
2055+
int offset = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer) - keep;
2056+
/* The buffer pointers cannot be NULL here; we have at least some bytes in the buffer */
20492057
memmove(parser->m_buffer, &parser->m_buffer[offset], parser->m_bufferEnd - parser->m_bufferPtr + keep);
20502058
parser->m_bufferEnd -= offset;
20512059
parser->m_bufferPtr -= offset;
20522060
}
20532061
#else
2054-
memmove(parser->m_buffer, parser->m_bufferPtr, parser->m_bufferEnd - parser->m_bufferPtr);
2055-
parser->m_bufferEnd = parser->m_buffer + (parser->m_bufferEnd - parser->m_bufferPtr);
2056-
parser->m_bufferPtr = parser->m_buffer;
2062+
if (parser->m_buffer && parser->m_bufferPtr) {
2063+
memmove(parser->m_buffer, parser->m_bufferPtr,
2064+
EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr));
2065+
parser->m_bufferEnd = parser->m_buffer +
2066+
EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr);
2067+
parser->m_bufferPtr = parser->m_buffer;
2068+
}
20572069
#endif /* not defined XML_CONTEXT_BYTES */
20582070
}
20592071
else {
20602072
char *newBuf;
2061-
int bufferSize = (int)(parser->m_bufferLim - parser->m_bufferPtr);
2073+
int bufferSize = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferPtr);
20622074
if (bufferSize == 0)
20632075
bufferSize = INIT_BUFFER_SIZE;
20642076
do {
@@ -2077,25 +2089,34 @@ XML_GetBuffer(XML_Parser parser, int len)
20772089
parser->m_bufferLim = newBuf + bufferSize;
20782090
#ifdef XML_CONTEXT_BYTES
20792091
if (parser->m_bufferPtr) {
2080-
int keep = (int)(parser->m_bufferPtr - parser->m_buffer);
2092+
int keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer);
20812093
if (keep > XML_CONTEXT_BYTES)
20822094
keep = XML_CONTEXT_BYTES;
2083-
memcpy(newBuf, &parser->m_bufferPtr[-keep], parser->m_bufferEnd - parser->m_bufferPtr + keep);
2095+
memcpy(newBuf, &parser->m_bufferPtr[-keep],
2096+
EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + keep);
20842097
FREE(parser, parser->m_buffer);
20852098
parser->m_buffer = newBuf;
2086-
parser->m_bufferEnd = parser->m_buffer + (parser->m_bufferEnd - parser->m_bufferPtr) + keep;
2099+
parser->m_bufferEnd = parser->m_buffer +
2100+
EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + keep;
20872101
parser->m_bufferPtr = parser->m_buffer + keep;
20882102
}
20892103
else {
2090-
parser->m_bufferEnd = newBuf + (parser->m_bufferEnd - parser->m_bufferPtr);
2104+
/* This must be a brand new buffer with no data in it yet */
2105+
parser->m_bufferEnd = newBuf;
20912106
parser->m_bufferPtr = parser->m_buffer = newBuf;
20922107
}
20932108
#else
20942109
if (parser->m_bufferPtr) {
2095-
memcpy(newBuf, parser->m_bufferPtr, parser->m_bufferEnd - parser->m_bufferPtr);
2110+
memcpy(newBuf, parser->m_bufferPtr,
2111+
EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr));
20962112
FREE(parser, parser->m_buffer);
2113+
parser->m_bufferEnd = newBuf +
2114+
EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr);
2115+
}
2116+
else {
2117+
/* This must be a brand new buffer with no data in it yet */
2118+
parser->m_bufferEnd = newBuf;
20972119
}
2098-
parser->m_bufferEnd = newBuf + (parser->m_bufferEnd - parser->m_bufferPtr);
20992120
parser->m_bufferPtr = parser->m_buffer = newBuf;
21002121
#endif /* not defined XML_CONTEXT_BYTES */
21012122
}
@@ -2908,9 +2929,11 @@ doContent(XML_Parser parser,
29082929
poolClear(&parser->m_tempPool);
29092930
freeBindings(parser, bindings);
29102931
}
2911-
if ((parser->m_tagLevel == 0) &&
2912-
!((parser->m_parsingStatus.parsing == XML_FINISHED) || (parser->m_parsingStatus.parsing == XML_SUSPENDED))) {
2913-
return epilogProcessor(parser, next, end, nextPtr);
2932+
if ((parser->m_tagLevel == 0) && (parser->m_parsingStatus.parsing != XML_FINISHED)) {
2933+
if (parser->m_parsingStatus.parsing == XML_SUSPENDED)
2934+
parser->m_processor = epilogProcessor;
2935+
else
2936+
return epilogProcessor(parser, next, end, nextPtr);
29142937
}
29152938
break;
29162939
case XML_TOK_END_TAG:
@@ -4746,8 +4769,8 @@ doProlog(XML_Parser parser,
47464769
return XML_ERROR_NO_MEMORY;
47474770
parser->m_declEntity->publicId = NULL;
47484771
}
4749-
/* fall through */
47504772
#endif /* XML_DTD */
4773+
/* fall through */
47514774
case XML_ROLE_ENTITY_SYSTEM_ID:
47524775
if (dtd->keepProcessing && parser->m_declEntity) {
47534776
parser->m_declEntity->systemId = poolStoreString(&dtd->pool, enc,
@@ -6643,7 +6666,6 @@ hash(XML_Parser parser, KEY s)
66436666
{
66446667
struct siphash state;
66456668
struct sipkey key;
6646-
(void)sip_tobin;
66476669
(void)sip24_valid;
66486670
copy_salt_to_sipkey(parser, &key);
66496671
sip24_init(&state, &key);

‎Modules/expat/xmltok_impl.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
*nextTokPtr = ptr; \
7575
return XML_TOK_INVALID; \
7676
} \
77+
/* fall through */ \
7778
case BT_NMSTRT: \
7879
case BT_HEX: \
7980
case BT_DIGIT: \
@@ -102,6 +103,7 @@
102103
*nextTokPtr = ptr; \
103104
return XML_TOK_INVALID; \
104105
} \
106+
/* fall through */ \
105107
case BT_NMSTRT: \
106108
case BT_HEX: \
107109
ptr += MINBPC(enc); \
@@ -602,7 +604,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
602604
return XML_TOK_INVALID;
603605
}
604606
}
605-
/* fall through */
607+
/* fall through */
606608
case BT_EQUALS:
607609
{
608610
int open;
@@ -1442,6 +1444,7 @@ PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
14421444
case BT_NMSTRT:
14431445
if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f))
14441446
break;
1447+
/* fall through */
14451448
default:
14461449
switch (BYTE_TO_ASCII(enc, ptr)) {
14471450
case 0x24: /* $ */
@@ -1659,8 +1662,8 @@ PREFIX(nameMatchesAscii)(const ENCODING *UNUSED_P(enc), const char *ptr1,
16591662
{
16601663
for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
16611664
if (end1 - ptr1 < MINBPC(enc)) {
1662-
/* This line cannot be executed. THe incoming data has already
1663-
* been tokenized once, so imcomplete characters like this have
1665+
/* This line cannot be executed. The incoming data has already
1666+
* been tokenized once, so incomplete characters like this have
16641667
* already been eliminated from the input. Retaining the
16651668
* paranoia check is still valuable, however.
16661669
*/

0 commit comments

Comments
 (0)
Failed to load comments.