]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Print error when oldsize is not equal to the current size.
authorQingqing Li <liqingqing3@huawei.com>
Thu, 22 Sep 2022 19:32:56 +0000 (15:32 -0400)
committerDJ Delorie <dj@redhat.com>
Thu, 22 Sep 2022 19:32:56 +0000 (15:32 -0400)
This is used to detect errors early.  The read of the oldsize is
not protected by any lock, so check this value to avoid causing
bigger mistakes.

Reviewed-by: DJ Delorie <dj@redhat.com>
malloc/malloc.c

index bfe19557379268eb72991b4c692a4fb8c6adabe8..67ac661256eb4a892f2818bca11eb437eeffc0e8 100644 (file)
@@ -4803,7 +4803,8 @@ _int_realloc (mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
 
   /* oldmem size */
   if (__builtin_expect (chunksize_nomask (oldp) <= CHUNK_HDR_SZ, 0)
-      || __builtin_expect (oldsize >= av->system_mem, 0))
+      || __builtin_expect (oldsize >= av->system_mem, 0)
+      || __builtin_expect (oldsize != chunksize (oldp), 0))
     malloc_printerr ("realloc(): invalid old size");
 
   check_inuse_chunk (av, oldp);