From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by sourceware.org (Postfix) with ESMTPS id 842903858028 for ; Fri, 26 Mar 2021 11:06:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 842903858028 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4F6Jxn4mpwzyPBt; Fri, 26 Mar 2021 19:03:57 +0800 (CST) Received: from [10.174.176.42] (10.174.176.42) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Mar 2021 19:05:48 +0800 To: "libc-alpha@sourceware.org" , , , Siddhesh Poyarekar From: liqingqing Subject: [PATCH] malloc: Print error when oldsize is not equal to the current size. CC: , , Liusirui Message-ID: <6c575d27-3d31-3d59-33b3-403ca9db03ab@huawei.com> Date: Fri, 26 Mar 2021 19:05:47 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.174.176.42] X-CFilter-Loop: Reflected X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Fri, 26 Mar 2021 11:06:04 -0000  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); -- 2.27.0