public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] malloc: Print error when oldsize is not equal to the current size.
@ 2022-09-22 19:51 DJ Delorie
  0 siblings, 0 replies; only message in thread
From: DJ Delorie @ 2022-09-22 19:51 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=774d43f27dbc730ee4b8b37bce4d5b3d5c0b74b6

commit 774d43f27dbc730ee4b8b37bce4d5b3d5c0b74b6
Author: Qingqing Li <liqingqing3@huawei.com>
Date:   Thu Sep 22 15:32:56 2022 -0400

    malloc: Print error when oldsize is not equal to the current size.
    
    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>

Diff:
---
 malloc/malloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index bfe1955737..67ac661256 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-22 19:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 19:51 [glibc] malloc: Print error when oldsize is not equal to the current size DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).