From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by sourceware.org (Postfix) with ESMTPS id 9BE993858028 for ; Thu, 1 Apr 2021 08:51:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9BE993858028 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9xhG2C5wz17PZK; Thu, 1 Apr 2021 16:49:50 +0800 (CST) Received: from [10.174.177.224] (10.174.177.224) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 1 Apr 2021 16:51:46 +0800 Subject: Re: [PATCH] malloc: Print error when oldsize is not equal to the current size. From: liqingqing To: "libc-alpha@sourceware.org" , , , Siddhesh Poyarekar CC: , , Liusirui References: <6c575d27-3d31-3d59-33b3-403ca9db03ab@huawei.com> Message-ID: <4574b99b-edac-d8dc-9141-79c3109d2fcc@huawei.com> Date: Thu, 1 Apr 2021 16:51:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <6c575d27-3d31-3d59-33b3-403ca9db03ab@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.174.177.224] X-CFilter-Loop: Reflected X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2021 08:52:01 -0000 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);