Skip to content

Commit

Permalink
CVE-2015-1283 Sanity check size calculations. r=peterv, a=abillings
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRahm authored and hartwork committed Mar 2, 2016
1 parent 3f5ed8f commit ba0f9c3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions expat/lib/xmlparse.c
Expand Up @@ -1678,6 +1678,10 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
void * XMLCALL
XML_GetBuffer(XML_Parser parser, int len)
{
if (len < 0) {
errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
switch (ps_parsing) {
case XML_SUSPENDED:
errorCode = XML_ERROR_SUSPENDED;
Expand All @@ -1689,8 +1693,11 @@ XML_GetBuffer(XML_Parser parser, int len)
}

if (len > bufferLim - bufferEnd) {
/* FIXME avoid integer overflow */
int neededSize = len + (int)(bufferEnd - bufferPtr);
if (neededSize < 0) {
errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
#ifdef XML_CONTEXT_BYTES
int keep = (int)(bufferPtr - buffer);

Expand Down Expand Up @@ -1719,7 +1726,11 @@ XML_GetBuffer(XML_Parser parser, int len)
bufferSize = INIT_BUFFER_SIZE;
do {
bufferSize *= 2;
} while (bufferSize < neededSize);
} while (bufferSize < neededSize && bufferSize > 0);
if (bufferSize <= 0) {
errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
newBuf = (char *)MALLOC(bufferSize);
if (newBuf == 0) {
errorCode = XML_ERROR_NO_MEMORY;
Expand Down

0 comments on commit ba0f9c3

Please sign in to comment.