Merge "fix a potential overflow with MALLOC_LIMIT"

This commit is contained in:
Pascal Massimino 2016-12-13 06:10:56 +00:00 committed by Gerrit Code Review
commit 827d3c5038

View File

@ -175,8 +175,12 @@ static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
} }
#endif #endif
#if defined(MALLOC_LIMIT) #if defined(MALLOC_LIMIT)
if (mem_limit > 0 && total_mem + total_size >= mem_limit) { if (mem_limit > 0) {
return 0; // fake fail! const uint64_t new_total_mem = (uint64_t)total_mem + total_size;
if (new_total_mem != (size_t)new_total_mem ||
new_total_mem > mem_limit) {
return 0; // fake fail!
}
} }
#endif #endif