Skip to content

Commit

Permalink
Check for integer overflow in memory debug code
Browse files Browse the repository at this point in the history
Fixes bug 783026.

Thanks to Pranjal Jumde for the report.
  • Loading branch information
nwellnhof committed Jun 6, 2017
1 parent 932cc98 commit 897dffb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions xmlmemory.c
Expand Up @@ -172,6 +172,13 @@ xmlMallocLoc(size_t size, const char * file, int line)

TEST_POINT

if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
"xmlMallocLoc : Unsigned overflow\n");
xmlMemoryDump();
return(NULL);
}

p = (MEMHDR *) malloc(RESERVE_SIZE+size);

if (!p) {
Expand Down Expand Up @@ -352,6 +359,13 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
#endif
xmlMutexUnlock(xmlMemMutex);

if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
"xmlMallocLoc : Unsigned overflow\n");
xmlMemoryDump();
return(NULL);
}

tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
if (!tmp) {
free(p);
Expand Down Expand Up @@ -499,6 +513,13 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
if (!xmlMemInitialized) xmlInitMemory();
TEST_POINT

if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
"xmlMallocLoc : Unsigned overflow\n");
xmlMemoryDump();
return(NULL);
}

p = (MEMHDR *) malloc(RESERVE_SIZE+size);
if (!p) {
goto error;
Expand Down

0 comments on commit 897dffb

Please sign in to comment.