mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
malloc: Fix a potential realloc issue with memory tagging
At an _int_free call site in realloc the wrong size was used for tag clearing: the chunk header of the next chunk was also cleared which in practice may work, but logically wrong. The tag clearing is moved before the memcpy to save a tag computation, this avoids a chunk2mem. Another chunk2mem is removed because newmem does not have to be recomputed. Whitespaces got fixed too. Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
@ -4851,14 +4851,14 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
void *oldmem = chunk2mem (oldp);
|
void *oldmem = chunk2rawmem (oldp);
|
||||||
|
size_t sz = CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ;
|
||||||
|
(void) TAG_REGION (oldmem, sz);
|
||||||
newmem = TAG_NEW_USABLE (newmem);
|
newmem = TAG_NEW_USABLE (newmem);
|
||||||
memcpy (newmem, oldmem,
|
memcpy (newmem, oldmem, sz);
|
||||||
CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ);
|
_int_free (av, oldp, 1);
|
||||||
(void) TAG_REGION (chunk2rawmem (oldp), oldsize);
|
check_inuse_chunk (av, newp);
|
||||||
_int_free (av, oldp, 1);
|
return newmem;
|
||||||
check_inuse_chunk (av, newp);
|
|
||||||
return chunk2mem (newp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user