diff options
author | Pale Moon <git-repo@palemoon.org> | 2015-05-21 11:44:10 +0200 |
---|---|---|
committer | Pale Moon <git-repo@palemoon.org> | 2015-05-21 11:44:10 +0200 |
commit | a30eba9e8964f5efaaae33bd6968c5936f010a7b (patch) | |
tree | 8561374a8078716f018b2e19277119c637287089 /parser/expat | |
parent | 403c1b01ab963c6ed4e27529726a55e763c1ccad (diff) | |
download | palemoon-gre-a30eba9e8964f5efaaae33bd6968c5936f010a7b.tar.gz |
Add some sanity checks in XML parser
Diffstat (limited to 'parser/expat')
-rw-r--r-- | parser/expat/lib/xmlparse.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/parser/expat/lib/xmlparse.c b/parser/expat/lib/xmlparse.c index 0f03c42ac..7898c03cb 100644 --- a/parser/expat/lib/xmlparse.c +++ b/parser/expat/lib/xmlparse.c @@ -1651,6 +1651,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; @@ -1662,8 +1668,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); @@ -1692,7 +1703,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; |