public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: DJ Delorie <dj@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] malloc: Print error when oldsize is not equal to the current size. Date: Thu, 22 Sep 2022 19:51:17 +0000 (GMT) [thread overview] Message-ID: <20220922195117.610933858D38@sourceware.org> (raw) 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);
reply other threads:[~2022-09-22 19:51 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220922195117.610933858D38@sourceware.org \ --to=dj@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /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: linkBe 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).