Don't access tail magic when reallocating invalid memory, as it would crash
This commit is contained in:
@@ -599,15 +599,17 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
|
|||||||
if (hdr->magic != MEMORY_HEADER_MAGIC ||
|
if (hdr->magic != MEMORY_HEADER_MAGIC ||
|
||||||
tail->magic != MEMORY_TAIL_MAGIC)
|
tail->magic != MEMORY_TAIL_MAGIC)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "reallocating invalid memory (%p): "
|
fprintf(stderr, "reallocating invalid memory (%p):\n"
|
||||||
"header magic 0x%x, tail magic 0x%x:\n",
|
"header magic 0x%x:\n", old, hdr->magic);
|
||||||
old, hdr->magic, tail->magic);
|
|
||||||
backtrace = backtrace_create(3);
|
backtrace = backtrace_create(3);
|
||||||
backtrace->log(backtrace, stderr, TRUE);
|
backtrace->log(backtrace, stderr, TRUE);
|
||||||
backtrace->destroy(backtrace);
|
backtrace->destroy(backtrace);
|
||||||
}
|
}
|
||||||
/* clear tail magic, allocate, set tail magic */
|
else
|
||||||
memset(&tail->magic, MEMORY_ALLOC_PATTERN, sizeof(tail->magic));
|
{
|
||||||
|
/* clear tail magic, allocate, set tail magic */
|
||||||
|
memset(&tail->magic, MEMORY_ALLOC_PATTERN, sizeof(tail->magic));
|
||||||
|
}
|
||||||
hdr = realloc(hdr, sizeof(memory_header_t) + bytes + sizeof(memory_tail_t));
|
hdr = realloc(hdr, sizeof(memory_header_t) + bytes + sizeof(memory_tail_t));
|
||||||
tail = ((void*)hdr) + bytes + sizeof(memory_header_t);
|
tail = ((void*)hdr) + bytes + sizeof(memory_header_t);
|
||||||
tail->magic = MEMORY_TAIL_MAGIC;
|
tail->magic = MEMORY_TAIL_MAGIC;
|
||||||
|
|||||||
Reference in New Issue
Block a user