public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: liqingqing <liqingqing3@huawei.com>
To: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
	<carlos@redhat.com>, <dj@redhat.com>,
	Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: <wuxu.wu@huawei.com>, <yebiaoxiang@huawei.com>,
	Liusirui <liusirui@huawei.com>
Subject: Re: [PATCH] malloc: Print error when oldsize is not equal to the current size.
Date: Thu, 1 Apr 2021 16:51:45 +0800	[thread overview]
Message-ID: <4574b99b-edac-d8dc-9141-79c3109d2fcc@huawei.com> (raw)
In-Reply-To: <6c575d27-3d31-3d59-33b3-403ca9db03ab@huawei.com>

ping again. 

the read of the oldsize is not protected by any lock, so check this value to avoid causing bigger mistakes. 

On 2021/3/26 19:05, liqingqing wrote:
>  This is used to detect errors early.
>
> ---
>  malloc/malloc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 530c792997..243be0da68 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -4784,7 +4784,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);

  reply	other threads:[~2021-04-01  8:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26 11:05 liqingqing
2021-04-01  8:51 ` liqingqing [this message]
2021-04-13 22:14   ` DJ Delorie
2021-04-23  2:23     ` liqingqing
2022-09-22 19:51 ` DJ Delorie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4574b99b-edac-d8dc-9141-79c3109d2fcc@huawei.com \
    --to=liqingqing3@huawei.com \
    --cc=carlos@redhat.com \
    --cc=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=liusirui@huawei.com \
    --cc=siddhesh@gotplt.org \
    --cc=wuxu.wu@huawei.com \
    --cc=yebiaoxiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).