40 lines
1.3 KiB
Diff
40 lines
1.3 KiB
Diff
Follow-up upstream fix for CVE-2015-1283 to not rely on undefined
|
|
behavior.
|
|
|
|
Adapted from a patch from Debian (found in Debian package version
|
|
2.1.0-6+deb8u2) to apply to upstream code:
|
|
|
|
https://sources.debian.net/src/expat/2.1.0-6%2Bdeb8u2/debian/patches/CVE-2015-1283-refix.patch/
|
|
|
|
---
|
|
lib/xmlparse.c | 6 ++++--
|
|
1 file changed, 4 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/lib/xmlparse.c b/lib/xmlparse.c
|
|
index 0f6f4cd..5c70c17 100644
|
|
--- a/lib/xmlparse.c
|
|
+++ b/lib/xmlparse.c
|
|
@@ -1727,7 +1727,8 @@ XML_GetBuffer(XML_Parser parser, int len)
|
|
}
|
|
|
|
if (len > bufferLim - bufferEnd) {
|
|
- int neededSize = len + (int)(bufferEnd - bufferPtr);
|
|
+ /* Do not invoke signed arithmetic overflow: */
|
|
+ int neededSize = (int) ((unsigned)len + (unsigned)(bufferEnd - bufferPtr));
|
|
if (neededSize < 0) {
|
|
errorCode = XML_ERROR_NO_MEMORY;
|
|
return NULL;
|
|
@@ -1759,7 +1760,8 @@ XML_GetBuffer(XML_Parser parser, int len)
|
|
if (bufferSize == 0)
|
|
bufferSize = INIT_BUFFER_SIZE;
|
|
do {
|
|
- bufferSize *= 2;
|
|
+ /* Do not invoke signed arithmetic overflow: */
|
|
+ bufferSize = (int) (2U * (unsigned) bufferSize);
|
|
} while (bufferSize < neededSize && bufferSize > 0);
|
|
if (bufferSize <= 0) {
|
|
errorCode = XML_ERROR_NO_MEMORY;
|
|
--
|
|
2.8.3
|
|
|