|
|
ed72f6 |
|
|
|
ed72f6 |
Patch as described below, plus a12e78cb1b290e26a2b669eff3664d76bb73a408.
|
|
|
ed72f6 |
|
|
|
ed72f6 |
>From cdfcb1b5c95e93b00ae9e9d25708b4a3bee72c15 Mon Sep 17 00:00:00 2001
|
|
|
ed72f6 |
From: Sebastian Pipping <sebastian@pipping.org>
|
|
|
ed72f6 |
Date: Mon, 2 May 2016 00:02:44 +0200
|
|
|
ed72f6 |
Subject: [PATCH] Address CVE-2016-0718 (/patch/ version 2.2.1)
|
|
|
ed72f6 |
|
|
|
ed72f6 |
* Out of bounds memory access when doing text conversion on malformed input
|
|
|
ed72f6 |
* Integer overflow related to memory allocation
|
|
|
ed72f6 |
|
|
|
ed72f6 |
Reported by Gustavo Grieco
|
|
|
ed72f6 |
|
|
|
ed72f6 |
Patch credits go to
|
|
|
ed72f6 |
* Christian Heimes
|
|
|
ed72f6 |
* Karl Waclawek
|
|
|
ed72f6 |
* Gustavo Grieco
|
|
|
ed72f6 |
* Sebastian Pipping
|
|
|
ed72f6 |
* Pascal Cuoq
|
|
|
ed72f6 |
---
|
|
|
ed72f6 |
expat/lib/xmlparse.c | 34 +++++++++-----
|
|
|
ed72f6 |
expat/lib/xmltok.c | 115 +++++++++++++++++++++++++++++++++++-------------
|
|
|
ed72f6 |
expat/lib/xmltok.h | 10 ++++-
|
|
|
ed72f6 |
expat/lib/xmltok_impl.c | 62 +++++++++++++-------------
|
|
|
ed72f6 |
4 files changed, 146 insertions(+), 75 deletions(-)
|
|
|
ed72f6 |
|
|
|
ed72f6 |
diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c
|
|
|
ed72f6 |
index e308c79..13e080d 100644
|
|
|
ed72f6 |
diff -uap expat-2.1.0/lib/xmlparse.c.cve0718 expat-2.1.0/lib/xmlparse.c
|
|
|
ed72f6 |
--- expat-2.1.0/lib/xmlparse.c.cve0718
|
|
|
ed72f6 |
+++ expat-2.1.0/lib/xmlparse.c
|
|
|
ed72f6 |
@@ -2415,11 +2415,11 @@
|
|
|
ed72f6 |
for (;;) {
|
|
|
ed72f6 |
int bufSize;
|
|
|
ed72f6 |
int convLen;
|
|
|
ed72f6 |
- XmlConvert(enc,
|
|
|
ed72f6 |
+ const enum XML_Convert_Result convert_res = XmlConvert(enc,
|
|
|
ed72f6 |
&fromPtr, rawNameEnd,
|
|
|
ed72f6 |
(ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);
|
|
|
ed72f6 |
convLen = (int)(toPtr - (XML_Char *)tag->buf);
|
|
|
ed72f6 |
- if (fromPtr == rawNameEnd) {
|
|
|
ed72f6 |
+ if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) {
|
|
|
ed72f6 |
tag->name.strLen = convLen;
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
@@ -2640,11 +2640,11 @@
|
|
|
ed72f6 |
if (MUST_CONVERT(enc, s)) {
|
|
|
ed72f6 |
for (;;) {
|
|
|
ed72f6 |
ICHAR *dataPtr = (ICHAR *)dataBuf;
|
|
|
ed72f6 |
- XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
|
|
|
ed72f6 |
+ const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
|
|
|
ed72f6 |
*eventEndPP = s;
|
|
|
ed72f6 |
charDataHandler(handlerArg, dataBuf,
|
|
|
ed72f6 |
(int)(dataPtr - (ICHAR *)dataBuf));
|
|
|
ed72f6 |
- if (s == next)
|
|
|
ed72f6 |
+ if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE))
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
*eventPP = s;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
@@ -3248,11 +3248,11 @@
|
|
|
ed72f6 |
if (MUST_CONVERT(enc, s)) {
|
|
|
ed72f6 |
for (;;) {
|
|
|
ed72f6 |
ICHAR *dataPtr = (ICHAR *)dataBuf;
|
|
|
ed72f6 |
- XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
|
|
|
ed72f6 |
+ const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
|
|
|
ed72f6 |
*eventEndPP = next;
|
|
|
ed72f6 |
charDataHandler(handlerArg, dataBuf,
|
|
|
ed72f6 |
(int)(dataPtr - (ICHAR *)dataBuf));
|
|
|
ed72f6 |
- if (s == next)
|
|
|
ed72f6 |
+ if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE))
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
*eventPP = s;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
@@ -5329,6 +5329,7 @@
|
|
|
ed72f6 |
const char *s, const char *end)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
if (MUST_CONVERT(enc, s)) {
|
|
|
ed72f6 |
+ enum XML_Convert_Result convert_res;
|
|
|
ed72f6 |
const char **eventPP;
|
|
|
ed72f6 |
const char **eventEndPP;
|
|
|
ed72f6 |
if (enc == encoding) {
|
|
|
ed72f6 |
@@ -5341,11 +5342,11 @@
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
do {
|
|
|
ed72f6 |
ICHAR *dataPtr = (ICHAR *)dataBuf;
|
|
|
ed72f6 |
- XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
|
|
|
ed72f6 |
+ convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
|
|
|
ed72f6 |
*eventEndPP = s;
|
|
|
ed72f6 |
defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf));
|
|
|
ed72f6 |
*eventPP = s;
|
|
|
ed72f6 |
- } while (s != end);
|
|
|
ed72f6 |
+ } while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVERT_INPUT_INCOMPLETE));
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
else
|
|
|
ed72f6 |
defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
|
|
|
ed72f6 |
@@ -6148,8 +6149,8 @@
|
|
|
ed72f6 |
if (!pool->ptr && !poolGrow(pool))
|
|
|
ed72f6 |
return NULL;
|
|
|
ed72f6 |
for (;;) {
|
|
|
ed72f6 |
- XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end);
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ const enum XML_Convert_Result convert_res = XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end);
|
|
|
ed72f6 |
+ if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE))
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
if (!poolGrow(pool))
|
|
|
ed72f6 |
return NULL;
|
|
|
ed72f6 |
@@ -6233,8 +6234,13 @@
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
if (pool->blocks && pool->start == pool->blocks->s) {
|
|
|
ed72f6 |
- int blockSize = (int)(pool->end - pool->start)*2;
|
|
|
ed72f6 |
- BLOCK *temp = (BLOCK *)
|
|
|
ed72f6 |
+ BLOCK *temp;
|
|
|
ed72f6 |
+ int blockSize = (int)((unsigned)(pool->end - pool->start)*2U);
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ if (blockSize < 0)
|
|
|
ed72f6 |
+ return XML_FALSE;
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ temp = (BLOCK *)
|
|
|
ed72f6 |
pool->mem->realloc_fcn(pool->blocks,
|
|
|
ed72f6 |
(offsetof(BLOCK, s)
|
|
|
ed72f6 |
+ blockSize * sizeof(XML_Char)));
|
|
|
ed72f6 |
@@ -6249,6 +6255,10 @@
|
|
|
ed72f6 |
else {
|
|
|
ed72f6 |
BLOCK *tem;
|
|
|
ed72f6 |
int blockSize = (int)(pool->end - pool->start);
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ if (blockSize < 0)
|
|
|
ed72f6 |
+ return XML_FALSE;
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
if (blockSize < INIT_BLOCK_SIZE)
|
|
|
ed72f6 |
blockSize = INIT_BLOCK_SIZE;
|
|
|
ed72f6 |
else
|
|
|
ed72f6 |
diff -uap expat-2.1.0/lib/xmltok.c.cve0718 expat-2.1.0/lib/xmltok.c
|
|
|
ed72f6 |
--- expat-2.1.0/lib/xmltok.c.cve0718
|
|
|
ed72f6 |
+++ expat-2.1.0/lib/xmltok.c
|
|
|
ed72f6 |
@@ -318,39 +318,55 @@
|
|
|
ed72f6 |
UTF8_cval4 = 0xf0
|
|
|
ed72f6 |
};
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
utf8_toUtf8(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
char **toP, const char *toLim)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
+ enum XML_Convert_Result res = XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
char *to;
|
|
|
ed72f6 |
const char *from;
|
|
|
ed72f6 |
if (fromLim - *fromP > toLim - *toP) {
|
|
|
ed72f6 |
/* Avoid copying partial characters. */
|
|
|
ed72f6 |
+ res = XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--)
|
|
|
ed72f6 |
if (((unsigned char)fromLim[-1] & 0xc0) != 0x80)
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- for (to = *toP, from = *fromP; from != fromLim; from++, to++)
|
|
|
ed72f6 |
+ for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++)
|
|
|
ed72f6 |
*to = *from;
|
|
|
ed72f6 |
*fromP = from;
|
|
|
ed72f6 |
*toP = to;
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ if ((to == toLim) && (from < fromLim))
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
+ else
|
|
|
ed72f6 |
+ return res;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
utf8_toUtf16(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
unsigned short **toP, const unsigned short *toLim)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
+ enum XML_Convert_Result res = XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
unsigned short *to = *toP;
|
|
|
ed72f6 |
const char *from = *fromP;
|
|
|
ed72f6 |
- while (from != fromLim && to != toLim) {
|
|
|
ed72f6 |
+ while (from < fromLim && to < toLim) {
|
|
|
ed72f6 |
switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) {
|
|
|
ed72f6 |
case BT_LEAD2:
|
|
|
ed72f6 |
+ if (fromLim - from < 2) {
|
|
|
ed72f6 |
+ res = XML_CONVERT_INPUT_INCOMPLETE;
|
|
|
ed72f6 |
+ break;
|
|
|
ed72f6 |
+ }
|
|
|
ed72f6 |
*to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f));
|
|
|
ed72f6 |
from += 2;
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
case BT_LEAD3:
|
|
|
ed72f6 |
+ if (fromLim - from < 3) {
|
|
|
ed72f6 |
+ res = XML_CONVERT_INPUT_INCOMPLETE;
|
|
|
ed72f6 |
+ break;
|
|
|
ed72f6 |
+ }
|
|
|
ed72f6 |
*to++ = (unsigned short)(((from[0] & 0xf) << 12)
|
|
|
ed72f6 |
| ((from[1] & 0x3f) << 6) | (from[2] & 0x3f));
|
|
|
ed72f6 |
from += 3;
|
|
|
ed72f6 |
@@ -358,8 +374,14 @@
|
|
|
ed72f6 |
case BT_LEAD4:
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
unsigned long n;
|
|
|
ed72f6 |
- if (to + 1 == toLim)
|
|
|
ed72f6 |
+ if (toLim - to < 2) {
|
|
|
ed72f6 |
+ res = XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
goto after;
|
|
|
ed72f6 |
+ }
|
|
|
ed72f6 |
+ if (fromLim - from < 4) {
|
|
|
ed72f6 |
+ res = XML_CONVERT_INPUT_INCOMPLETE;
|
|
|
ed72f6 |
+ goto after;
|
|
|
ed72f6 |
+ }
|
|
|
ed72f6 |
n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12)
|
|
|
ed72f6 |
| ((from[2] & 0x3f) << 6) | (from[3] & 0x3f);
|
|
|
ed72f6 |
n -= 0x10000;
|
|
|
ed72f6 |
@@ -377,6 +399,7 @@
|
|
|
ed72f6 |
after:
|
|
|
ed72f6 |
*fromP = from;
|
|
|
ed72f6 |
*toP = to;
|
|
|
ed72f6 |
+ return res;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
#ifdef XML_NS
|
|
|
ed72f6 |
@@ -425,7 +448,7 @@
|
|
|
ed72f6 |
STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
|
|
|
ed72f6 |
};
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
latin1_toUtf8(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
char **toP, const char *toLim)
|
|
|
ed72f6 |
@@ -433,30 +456,35 @@
|
|
|
ed72f6 |
for (;;) {
|
|
|
ed72f6 |
unsigned char c;
|
|
|
ed72f6 |
if (*fromP == fromLim)
|
|
|
ed72f6 |
- break;
|
|
|
ed72f6 |
+ return XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
c = (unsigned char)**fromP;
|
|
|
ed72f6 |
if (c & 0x80) {
|
|
|
ed72f6 |
if (toLim - *toP < 2)
|
|
|
ed72f6 |
- break;
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
*(*toP)++ = (char)((c >> 6) | UTF8_cval2);
|
|
|
ed72f6 |
*(*toP)++ = (char)((c & 0x3f) | 0x80);
|
|
|
ed72f6 |
(*fromP)++;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
else {
|
|
|
ed72f6 |
if (*toP == toLim)
|
|
|
ed72f6 |
- break;
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
*(*toP)++ = *(*fromP)++;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
latin1_toUtf16(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
unsigned short **toP, const unsigned short *toLim)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- while (*fromP != fromLim && *toP != toLim)
|
|
|
ed72f6 |
+ while (*fromP < fromLim && *toP < toLim)
|
|
|
ed72f6 |
*(*toP)++ = (unsigned char)*(*fromP)++;
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ if ((*toP == toLim) && (*fromP < fromLim))
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
+ else
|
|
|
ed72f6 |
+ return XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
#ifdef XML_NS
|
|
|
ed72f6 |
@@ -483,13 +511,18 @@
|
|
|
ed72f6 |
STANDARD_VTABLE(sb_)
|
|
|
ed72f6 |
};
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
ascii_toUtf8(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
char **toP, const char *toLim)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- while (*fromP != fromLim && *toP != toLim)
|
|
|
ed72f6 |
+ while (*fromP < fromLim && *toP < toLim)
|
|
|
ed72f6 |
*(*toP)++ = *(*fromP)++;
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ if ((*toP == toLim) && (*fromP < fromLim))
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
+ else
|
|
|
ed72f6 |
+ return XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
#ifdef XML_NS
|
|
|
ed72f6 |
@@ -536,13 +569,14 @@
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
#define DEFINE_UTF16_TO_UTF8(E) \
|
|
|
ed72f6 |
-static void PTRCALL \
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL \
|
|
|
ed72f6 |
E ## toUtf8(const ENCODING *enc, \
|
|
|
ed72f6 |
const char **fromP, const char *fromLim, \
|
|
|
ed72f6 |
char **toP, const char *toLim) \
|
|
|
ed72f6 |
{ \
|
|
|
ed72f6 |
- const char *from; \
|
|
|
ed72f6 |
- for (from = *fromP; from != fromLim; from += 2) { \
|
|
|
ed72f6 |
+ const char *from = *fromP; \
|
|
|
ed72f6 |
+ fromLim = from + (((fromLim - from) >> 1) << 1); /* shrink to even */ \
|
|
|
ed72f6 |
+ for (; from < fromLim; from += 2) { \
|
|
|
ed72f6 |
int plane; \
|
|
|
ed72f6 |
unsigned char lo2; \
|
|
|
ed72f6 |
unsigned char lo = GET_LO(from); \
|
|
|
ed72f6 |
@@ -552,7 +586,7 @@
|
|
|
ed72f6 |
if (lo < 0x80) { \
|
|
|
ed72f6 |
if (*toP == toLim) { \
|
|
|
ed72f6 |
*fromP = from; \
|
|
|
ed72f6 |
- return; \
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED; \
|
|
|
ed72f6 |
} \
|
|
|
ed72f6 |
*(*toP)++ = lo; \
|
|
|
ed72f6 |
break; \
|
|
|
ed72f6 |
@@ -562,7 +596,7 @@
|
|
|
ed72f6 |
case 0x4: case 0x5: case 0x6: case 0x7: \
|
|
|
ed72f6 |
if (toLim - *toP < 2) { \
|
|
|
ed72f6 |
*fromP = from; \
|
|
|
ed72f6 |
- return; \
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED; \
|
|
|
ed72f6 |
} \
|
|
|
ed72f6 |
*(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \
|
|
|
ed72f6 |
*(*toP)++ = ((lo & 0x3f) | 0x80); \
|
|
|
ed72f6 |
@@ -570,7 +604,7 @@
|
|
|
ed72f6 |
default: \
|
|
|
ed72f6 |
if (toLim - *toP < 3) { \
|
|
|
ed72f6 |
*fromP = from; \
|
|
|
ed72f6 |
- return; \
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED; \
|
|
|
ed72f6 |
} \
|
|
|
ed72f6 |
/* 16 bits divided 4, 6, 6 amongst 3 bytes */ \
|
|
|
ed72f6 |
*(*toP)++ = ((hi >> 4) | UTF8_cval3); \
|
|
|
ed72f6 |
@@ -580,7 +614,11 @@
|
|
|
ed72f6 |
case 0xD8: case 0xD9: case 0xDA: case 0xDB: \
|
|
|
ed72f6 |
if (toLim - *toP < 4) { \
|
|
|
ed72f6 |
*fromP = from; \
|
|
|
ed72f6 |
- return; \
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED; \
|
|
|
ed72f6 |
+ } \
|
|
|
ed72f6 |
+ if (fromLim - from < 4) { \
|
|
|
ed72f6 |
+ *fromP = from; \
|
|
|
ed72f6 |
+ return XML_CONVERT_INPUT_INCOMPLETE; \
|
|
|
ed72f6 |
} \
|
|
|
ed72f6 |
plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \
|
|
|
ed72f6 |
*(*toP)++ = ((plane >> 2) | UTF8_cval4); \
|
|
|
ed72f6 |
@@ -596,20 +634,32 @@
|
|
|
ed72f6 |
} \
|
|
|
ed72f6 |
} \
|
|
|
ed72f6 |
*fromP = from; \
|
|
|
ed72f6 |
+ if (from < fromLim) \
|
|
|
ed72f6 |
+ return XML_CONVERT_INPUT_INCOMPLETE; \
|
|
|
ed72f6 |
+ else \
|
|
|
ed72f6 |
+ return XML_CONVERT_COMPLETED; \
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
#define DEFINE_UTF16_TO_UTF16(E) \
|
|
|
ed72f6 |
-static void PTRCALL \
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL \
|
|
|
ed72f6 |
E ## toUtf16(const ENCODING *enc, \
|
|
|
ed72f6 |
const char **fromP, const char *fromLim, \
|
|
|
ed72f6 |
unsigned short **toP, const unsigned short *toLim) \
|
|
|
ed72f6 |
{ \
|
|
|
ed72f6 |
+ enum XML_Convert_Result res = XML_CONVERT_COMPLETED; \
|
|
|
ed72f6 |
+ fromLim = *fromP + (((fromLim - *fromP) >> 1) << 1); /* shrink to even */ \
|
|
|
ed72f6 |
/* Avoid copying first half only of surrogate */ \
|
|
|
ed72f6 |
if (fromLim - *fromP > ((toLim - *toP) << 1) \
|
|
|
ed72f6 |
- && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \
|
|
|
ed72f6 |
+ && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) { \
|
|
|
ed72f6 |
fromLim -= 2; \
|
|
|
ed72f6 |
- for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \
|
|
|
ed72f6 |
+ res = XML_CONVERT_INPUT_INCOMPLETE; \
|
|
|
ed72f6 |
+ } \
|
|
|
ed72f6 |
+ for (; *fromP < fromLim && *toP < toLim; *fromP += 2) \
|
|
|
ed72f6 |
*(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
|
|
|
ed72f6 |
+ if ((*toP == toLim) && (*fromP < fromLim)) \
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED; \
|
|
|
ed72f6 |
+ else \
|
|
|
ed72f6 |
+ return res; \
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
#define SET2(ptr, ch) \
|
|
|
ed72f6 |
@@ -1288,7 +1338,7 @@
|
|
|
ed72f6 |
return (c & ~0xFFFF) || checkCharRefNumber(c) < 0;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
unknown_toUtf8(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
char **toP, const char *toLim)
|
|
|
ed72f6 |
@@ -1299,21 +1349,21 @@
|
|
|
ed72f6 |
const char *utf8;
|
|
|
ed72f6 |
int n;
|
|
|
ed72f6 |
if (*fromP == fromLim)
|
|
|
ed72f6 |
- break;
|
|
|
ed72f6 |
+ return XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
utf8 = uenc->utf8[(unsigned char)**fromP];
|
|
|
ed72f6 |
n = *utf8++;
|
|
|
ed72f6 |
if (n == 0) {
|
|
|
ed72f6 |
int c = uenc->convert(uenc->userData, *fromP);
|
|
|
ed72f6 |
n = XmlUtf8Encode(c, buf);
|
|
|
ed72f6 |
if (n > toLim - *toP)
|
|
|
ed72f6 |
- break;
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
utf8 = buf;
|
|
|
ed72f6 |
*fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP]
|
|
|
ed72f6 |
- (BT_LEAD2 - 2));
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
else {
|
|
|
ed72f6 |
if (n > toLim - *toP)
|
|
|
ed72f6 |
- break;
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
(*fromP)++;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
do {
|
|
|
ed72f6 |
@@ -1322,13 +1372,13 @@
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
-static void PTRCALL
|
|
|
ed72f6 |
+static enum XML_Convert_Result PTRCALL
|
|
|
ed72f6 |
unknown_toUtf16(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP, const char *fromLim,
|
|
|
ed72f6 |
unsigned short **toP, const unsigned short *toLim)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
|
|
|
ed72f6 |
- while (*fromP != fromLim && *toP != toLim) {
|
|
|
ed72f6 |
+ while (*fromP < fromLim && *toP < toLim) {
|
|
|
ed72f6 |
unsigned short c = uenc->utf16[(unsigned char)**fromP];
|
|
|
ed72f6 |
if (c == 0) {
|
|
|
ed72f6 |
c = (unsigned short)
|
|
|
ed72f6 |
@@ -1340,6 +1390,11 @@
|
|
|
ed72f6 |
(*fromP)++;
|
|
|
ed72f6 |
*(*toP)++ = c;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
+ if ((*toP == toLim) && (*fromP < fromLim))
|
|
|
ed72f6 |
+ return XML_CONVERT_OUTPUT_EXHAUSTED;
|
|
|
ed72f6 |
+ else
|
|
|
ed72f6 |
+ return XML_CONVERT_COMPLETED;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
|
|
|
ed72f6 |
ENCODING *
|
|
|
ed72f6 |
@@ -1503,7 +1558,7 @@
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
const ENCODING **encPtr;
|
|
|
ed72f6 |
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ if (ptr >= end)
|
|
|
ed72f6 |
return XML_TOK_NONE;
|
|
|
ed72f6 |
encPtr = enc->encPtr;
|
|
|
ed72f6 |
if (ptr + 1 == end) {
|
|
|
ed72f6 |
diff -uap expat-2.1.0/lib/xmltok.h.cve0718 expat-2.1.0/lib/xmltok.h
|
|
|
ed72f6 |
--- expat-2.1.0/lib/xmltok.h.cve0718
|
|
|
ed72f6 |
+++ expat-2.1.0/lib/xmltok.h
|
|
|
ed72f6 |
@@ -130,6 +130,12 @@
|
|
|
ed72f6 |
const char *,
|
|
|
ed72f6 |
const char **);
|
|
|
ed72f6 |
|
|
|
ed72f6 |
+enum XML_Convert_Result {
|
|
|
ed72f6 |
+ XML_CONVERT_COMPLETED = 0,
|
|
|
ed72f6 |
+ XML_CONVERT_INPUT_INCOMPLETE = 1,
|
|
|
ed72f6 |
+ XML_CONVERT_OUTPUT_EXHAUSTED = 2 /* and therefore potentially input remaining as well */
|
|
|
ed72f6 |
+};
|
|
|
ed72f6 |
+
|
|
|
ed72f6 |
struct encoding {
|
|
|
ed72f6 |
SCANNER scanners[XML_N_STATES];
|
|
|
ed72f6 |
SCANNER literalScanners[XML_N_LITERAL_TYPES];
|
|
|
ed72f6 |
@@ -158,12 +164,12 @@
|
|
|
ed72f6 |
const char *ptr,
|
|
|
ed72f6 |
const char *end,
|
|
|
ed72f6 |
const char **badPtr);
|
|
|
ed72f6 |
- void (PTRCALL *utf8Convert)(const ENCODING *enc,
|
|
|
ed72f6 |
+ enum XML_Convert_Result (PTRCALL *utf8Convert)(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP,
|
|
|
ed72f6 |
const char *fromLim,
|
|
|
ed72f6 |
char **toP,
|
|
|
ed72f6 |
const char *toLim);
|
|
|
ed72f6 |
- void (PTRCALL *utf16Convert)(const ENCODING *enc,
|
|
|
ed72f6 |
+ enum XML_Convert_Result (PTRCALL *utf16Convert)(const ENCODING *enc,
|
|
|
ed72f6 |
const char **fromP,
|
|
|
ed72f6 |
const char *fromLim,
|
|
|
ed72f6 |
unsigned short **toP,
|
|
|
ed72f6 |
diff -uap expat-2.1.0/lib/xmltok_impl.c.cve0718 expat-2.1.0/lib/xmltok_impl.c
|
|
|
ed72f6 |
--- expat-2.1.0/lib/xmltok_impl.c.cve0718
|
|
|
ed72f6 |
+++ expat-2.1.0/lib/xmltok_impl.c
|
|
|
ed72f6 |
@@ -93,13 +93,13 @@
|
|
|
ed72f6 |
PREFIX(scanComment)(const ENCODING *enc, const char *ptr,
|
|
|
ed72f6 |
const char *end, const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- if (ptr != end) {
|
|
|
ed72f6 |
+ if (ptr < end) {
|
|
|
ed72f6 |
if (!CHAR_MATCHES(enc, ptr, ASCII_MINUS)) {
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
INVALID_CASES(ptr, nextTokPtr)
|
|
|
ed72f6 |
case BT_MINUS:
|
|
|
ed72f6 |
@@ -147,7 +147,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
case BT_PERCNT:
|
|
|
ed72f6 |
if (ptr + MINBPC(enc) == end)
|
|
|
ed72f6 |
@@ -233,7 +233,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_S: case BT_CR: case BT_LF:
|
|
|
ed72f6 |
@@ -242,7 +242,7 @@
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
INVALID_CASES(ptr, nextTokPtr)
|
|
|
ed72f6 |
case BT_QUEST:
|
|
|
ed72f6 |
@@ -305,7 +305,7 @@
|
|
|
ed72f6 |
PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr,
|
|
|
ed72f6 |
const char *end, const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ if (ptr >= end)
|
|
|
ed72f6 |
return XML_TOK_NONE;
|
|
|
ed72f6 |
if (MINBPC(enc) > 1) {
|
|
|
ed72f6 |
size_t n = end - ptr;
|
|
|
ed72f6 |
@@ -348,7 +348,7 @@
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
#define LEAD_CASE(n) \
|
|
|
ed72f6 |
case BT_LEAD ## n: \
|
|
|
ed72f6 |
@@ -391,11 +391,11 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_S: case BT_CR: case BT_LF:
|
|
|
ed72f6 |
- for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
+ for (ptr += MINBPC(enc); ptr < end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
case BT_S: case BT_CR: case BT_LF:
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
@@ -432,7 +432,7 @@
|
|
|
ed72f6 |
PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr,
|
|
|
ed72f6 |
const char *end, const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- if (ptr != end) {
|
|
|
ed72f6 |
+ if (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
case BT_DIGIT:
|
|
|
ed72f6 |
case BT_HEX:
|
|
|
ed72f6 |
@@ -441,7 +441,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
+ for (ptr += MINBPC(enc); ptr < end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
case BT_DIGIT:
|
|
|
ed72f6 |
case BT_HEX:
|
|
|
ed72f6 |
@@ -464,7 +464,7 @@
|
|
|
ed72f6 |
PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr,
|
|
|
ed72f6 |
const char *end, const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- if (ptr != end) {
|
|
|
ed72f6 |
+ if (ptr < end) {
|
|
|
ed72f6 |
if (CHAR_MATCHES(enc, ptr, ASCII_x))
|
|
|
ed72f6 |
return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr);
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
@@ -474,7 +474,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
+ for (ptr += MINBPC(enc); ptr < end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
case BT_DIGIT:
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
@@ -506,7 +506,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_SEMI:
|
|
|
ed72f6 |
@@ -529,7 +529,7 @@
|
|
|
ed72f6 |
#ifdef XML_NS
|
|
|
ed72f6 |
int hadColon = 0;
|
|
|
ed72f6 |
#endif
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
#ifdef XML_NS
|
|
|
ed72f6 |
@@ -716,7 +716,7 @@
|
|
|
ed72f6 |
hadColon = 0;
|
|
|
ed72f6 |
#endif
|
|
|
ed72f6 |
/* we have a start-tag */
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
#ifdef XML_NS
|
|
|
ed72f6 |
@@ -740,7 +740,7 @@
|
|
|
ed72f6 |
case BT_S: case BT_CR: case BT_LF:
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_GT:
|
|
|
ed72f6 |
@@ -785,7 +785,7 @@
|
|
|
ed72f6 |
PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end,
|
|
|
ed72f6 |
const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ if (ptr >= end)
|
|
|
ed72f6 |
return XML_TOK_NONE;
|
|
|
ed72f6 |
if (MINBPC(enc) > 1) {
|
|
|
ed72f6 |
size_t n = end - ptr;
|
|
|
ed72f6 |
@@ -832,7 +832,7 @@
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
break;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
#define LEAD_CASE(n) \
|
|
|
ed72f6 |
case BT_LEAD ## n: \
|
|
|
ed72f6 |
@@ -895,7 +895,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_SEMI:
|
|
|
ed72f6 |
@@ -921,7 +921,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_CR: case BT_LF: case BT_S:
|
|
|
ed72f6 |
@@ -941,7 +941,7 @@
|
|
|
ed72f6 |
const char *ptr, const char *end,
|
|
|
ed72f6 |
const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
int t = BYTE_TYPE(enc, ptr);
|
|
|
ed72f6 |
switch (t) {
|
|
|
ed72f6 |
INVALID_CASES(ptr, nextTokPtr)
|
|
|
ed72f6 |
@@ -973,7 +973,7 @@
|
|
|
ed72f6 |
const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
int tok;
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ if (ptr >= end)
|
|
|
ed72f6 |
return XML_TOK_NONE;
|
|
|
ed72f6 |
if (MINBPC(enc) > 1) {
|
|
|
ed72f6 |
size_t n = end - ptr;
|
|
|
ed72f6 |
@@ -1141,7 +1141,7 @@
|
|
|
ed72f6 |
*nextTokPtr = ptr;
|
|
|
ed72f6 |
return XML_TOK_INVALID;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
CHECK_NAME_CASES(enc, ptr, end, nextTokPtr)
|
|
|
ed72f6 |
case BT_GT: case BT_RPAR: case BT_COMMA:
|
|
|
ed72f6 |
@@ -1204,10 +1204,10 @@
|
|
|
ed72f6 |
const char *end, const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
const char *start;
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ if (ptr >= end)
|
|
|
ed72f6 |
return XML_TOK_NONE;
|
|
|
ed72f6 |
start = ptr;
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
#define LEAD_CASE(n) \
|
|
|
ed72f6 |
case BT_LEAD ## n: ptr += n; break;
|
|
|
ed72f6 |
@@ -1262,10 +1262,10 @@
|
|
|
ed72f6 |
const char *end, const char **nextTokPtr)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
const char *start;
|
|
|
ed72f6 |
- if (ptr == end)
|
|
|
ed72f6 |
+ if (ptr >= end)
|
|
|
ed72f6 |
return XML_TOK_NONE;
|
|
|
ed72f6 |
start = ptr;
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
#define LEAD_CASE(n) \
|
|
|
ed72f6 |
case BT_LEAD ## n: ptr += n; break;
|
|
|
ed72f6 |
@@ -1326,7 +1326,7 @@
|
|
|
ed72f6 |
end = ptr + n;
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
}
|
|
|
ed72f6 |
- while (ptr != end) {
|
|
|
ed72f6 |
+ while (ptr < end) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
INVALID_CASES(ptr, nextTokPtr)
|
|
|
ed72f6 |
case BT_LT:
|
|
|
ed72f6 |
@@ -1373,7 +1373,7 @@
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
end -= MINBPC(enc);
|
|
|
ed72f6 |
- for (; ptr != end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
+ for (; ptr < end; ptr += MINBPC(enc)) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
case BT_DIGIT:
|
|
|
ed72f6 |
case BT_HEX:
|
|
|
ed72f6 |
@@ -1744,7 +1744,7 @@
|
|
|
ed72f6 |
const char *end,
|
|
|
ed72f6 |
POSITION *pos)
|
|
|
ed72f6 |
{
|
|
|
ed72f6 |
- while (ptr < end) {
|
|
|
ed72f6 |
+ while (end - ptr >= MINBPC(enc)) {
|
|
|
ed72f6 |
switch (BYTE_TYPE(enc, ptr)) {
|
|
|
ed72f6 |
#define LEAD_CASE(n) \
|
|
|
ed72f6 |
case BT_LEAD ## n: \
|
|
|
ed72f6 |
@@ -1760,7 +1760,7 @@
|
|
|
ed72f6 |
case BT_CR:
|
|
|
ed72f6 |
pos->lineNumber++;
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
- if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF)
|
|
|
ed72f6 |
+ if (ptr < end && BYTE_TYPE(enc, ptr) == BT_LF)
|
|
|
ed72f6 |
ptr += MINBPC(enc);
|
|
|
ed72f6 |
pos->columnNumber = (XML_Size)-1;
|
|
|
ed72f6 |
break;
|