diff options
author | Xin LI <delphij@FreeBSD.org> | 2015-08-18 19:30:04 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2015-08-18 19:30:04 +0000 |
commit | 79b015331632b33f22bc8d8fef136c2672f2241f (patch) | |
tree | 6e8c0a05dbf0287fc8541d989fcee3bdc37a4c9e /contrib/expat | |
parent | 2c98c61dad8dd6cf82061405a67694c4736a0838 (diff) | |
download | src-test2-79b015331632b33f22bc8d8fef136c2672f2241f.tar.gz src-test2-79b015331632b33f22bc8d8fef136c2672f2241f.zip |
Fix multiple integer overflows in expat.
Security: CVE-2015-1283
Security: FreeBSD-SA-15:20.expat
Notes
Notes:
svn path=/head/; revision=286899
Diffstat (limited to 'contrib/expat')
-rw-r--r-- | contrib/expat/lib/xmlparse.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/contrib/expat/lib/xmlparse.c b/contrib/expat/lib/xmlparse.c index f35aa36ba8a7..ede7b5bb6673 100644 --- a/contrib/expat/lib/xmlparse.c +++ b/contrib/expat/lib/xmlparse.c @@ -1678,6 +1678,12 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal) void * XMLCALL XML_GetBuffer(XML_Parser parser, int len) { +/* BEGIN MOZILLA CHANGE (sanity check len) */ + if (len < 0) { + errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } +/* END MOZILLA CHANGE */ switch (ps_parsing) { case XML_SUSPENDED: errorCode = XML_ERROR_SUSPENDED; @@ -1689,8 +1695,13 @@ XML_GetBuffer(XML_Parser parser, int len) } if (len > bufferLim - bufferEnd) { - /* FIXME avoid integer overflow */ int neededSize = len + (int)(bufferEnd - bufferPtr); +/* BEGIN MOZILLA CHANGE (sanity check neededSize) */ + if (neededSize < 0) { + errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } +/* END MOZILLA CHANGE */ #ifdef XML_CONTEXT_BYTES int keep = (int)(bufferPtr - buffer); @@ -1719,7 +1730,15 @@ XML_GetBuffer(XML_Parser parser, int len) bufferSize = INIT_BUFFER_SIZE; do { bufferSize *= 2; - } while (bufferSize < neededSize); +/* BEGIN MOZILLA CHANGE (prevent infinite loop on overflow) */ + } while (bufferSize < neededSize && bufferSize > 0); +/* END MOZILLA CHANGE */ +/* BEGIN MOZILLA CHANGE (sanity check bufferSize) */ + if (bufferSize <= 0) { + errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } +/* END MOZILLA CHANGE */ newBuf = (char *)MALLOC(bufferSize); if (newBuf == 0) { errorCode = XML_ERROR_NO_MEMORY; |