In realloc(9), determine size of the original block based on

UMA_SLAB_MALLOC flag.
In some circumstances (I observed it when I was doing a lot of reallocs)
UMA_SLAB_MALLOC can be set even if us_keg != NULL.

If this is the case we have wonderful, silent data corruption, because less
data is copied to the newly allocated region than should be.

I'm not sure when this bug was introduced, it could be there undetected
for years now, as we don't have a lot of realloc(9) consumers and it was
hard to reproduce it...
...but what I know for sure, is that I don't want to know who introduce
the bug:) It took me two/three days to track it down (of course most of
the time I was looking for the bug in my own code).
This commit is contained in:
Pawel Jakub Dawidek 2005-12-28 01:53:13 +00:00
parent 333051eeb3
commit 619f284195
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=153769

View File

@ -437,7 +437,7 @@ if (mtp == M_SUBPROC) {
("realloc: address %p out of range", (void *)addr));
/* Get the size of the original block */
if (slab->us_keg)
if (!(slab->us_flags & UMA_SLAB_MALLOC))
alloc = slab->us_keg->uk_size;
else
alloc = slab->us_size;