From nobody Sat Apr 20 05:28:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1616780033; cv=none; d=zohomail.com; s=zohoarc; b=YvyAEfcxNgyS8Z3pLHWgTsvbSPaGbVcKtUeWuQ/tMLzJjMG5vtPKVSISd70uB8/0SBS/IYB6ARTVhcaGuvJM2AGBi2EQY35fvv0UtIgbFPp6YRIM45lSUqnJi1yVYoqk3jGBHs1GdThgSt3JVb7cxx8LX1ogkX0u0ZXLZxJvJ4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616780033; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:To; bh=S3qXsxw3Q1GgwkhZKKPjcKTqrm6S+NK/A2bYcVXJajg=; b=nVBD20j+bKMbKiEEu8ACWF0gWSdgu26eiOj4t/67iPoQ8DGSpNtP0zxzn2KvOIrOFzlJutPtegU8cw4wTfZxdN+XyaRdwx4yu9J0nPJHvGPrgQuk2mOZZMaJvOau7lu50bHfupf7xXFmC0T/HZQjV3mflkDEZTXT8L948L4rlW0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1616780033457447.99684627047725; Fri, 26 Mar 2021 10:33:53 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 65D1B16A09C3; Fri, 26 Mar 2021 17:33:49 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 9361416A09B5 for ; Tue, 23 Mar 2021 03:03:42 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4F4GNs16grzYNBg for ; Tue, 23 Mar 2021 11:01:49 +0800 (CST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) DGGEML404-HUB.china.huawei.com (10.3.17.39) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 23 Mar 2021 11:03:37 +0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Tue, 23 Mar 2021 11:03:37 +0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) dggpemm500014.china.huawei.com ([7.185.36.153]) with mapi id 15.01.2106.013; Tue, 23 Mar 2021 11:03:37 +0800 From: "likejun (A)" To: "seabios@seabios.org" Thread-Topic: [PATCH] malloc: Add check to avoid dereference NULL pointer. Thread-Index: AdcfkRDxlXEvikGbRw+XRneeeIZXoQ== Date: Tue, 23 Mar 2021 03:03:37 +0000 Message-ID: <231b2266ae9e41b882d773a8a4c677c5@huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: MIME-Version: 1.0 X-CFilter-Loop: Reflected X-MailFrom: likejun6@huawei.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1 Message-ID-Hash: ABDXEGPKF42AKKDJL7YUG2OBJKZ6Y6QR X-Message-ID-Hash: ABDXEGPKF42AKKDJL7YUG2OBJKZ6Y6QR X-Mailman-Approved-At: Fri, 26 Mar 2021 17:33:39 +0000 CC: Xiexiangyou , yebiaoxiang X-Mailman-Version: 3.3.4b1 Precedence: list Subject: [SeaBIOS] [PATCH] malloc: Add check to avoid dereference NULL pointer. List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: multipart/mixed; boundary="===============2294095467712185558==" Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: - --===============2294095467712185558== Content-Language: zh-CN Content-Type: multipart/alternative; boundary="_000_231b2266ae9e41b882d773a8a4c677c5huaweicom_" --_000_231b2266ae9e41b882d773a8a4c677c5huaweicom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Kejun Li > Date: Mon, 22 Mar 2021 14:03:10 +0800 Subject: [PATCH] malloc: Add check to avoid dereference NULL pointer. info =3D alloc_find_lowest() may return NULL, should check before dereference it to avoid potential coredump. Signed-off-by: Kejun Li > --- src/malloc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/malloc.c b/src/malloc.c index 3733855..d355b77 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -544,10 +544,12 @@ malloc_prepboot(void) // Clear unused f-seg ram. struct allocinfo_s *info =3D alloc_find_lowest(&ZoneFSeg); - u32 size =3D info->range_end - info->range_start; - memset(memremap(info->range_start, size), 0, size); - dprintf(1, "Space available for UMB: %x-%x, %x-%x\n" - , RomEnd, base, info->range_start, info->range_end); + if (info) { + u32 size =3D info->range_end - info->range_start; + memset(memremap(info->range_start, size), 0, size); + dprintf(1, "Space available for UMB: %x-%x, %x-%x\n" + , RomEnd, base, info->range_start, info->range_end); + } // Give back unused high ram. info =3D alloc_find_lowest(&ZoneHigh); -- 2.19.1 --_000_231b2266ae9e41b882d773a8a4c677c5huaweicom_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

From: Kejun Li <likejun6@huawei.com>

Date: Mon, 22 Mar 2021 14:03= :10 +0800

Subject: [PATCH] malloc: Add= check to avoid dereference NULL pointer.

 

info =3D alloc_find_lowest()= may return NULL, should check before

dereference it to avoid pote= ntial coredump.

 

Signed-off-by: Kejun Li <= likejun6@huawei.com>

---

src/malloc.c | 10 ++= ++++----

1 file changed, 6 insertions= (+), 4 deletions(-)

 

diff --git a/src/malloc.c b/= src/malloc.c index 3733855..d355b77 100644

--- a/src/malloc.c

+++ b/src/malloc= .c

@@ -544,10 +544,12 @@ ma= lloc_prepboot(void)

 

     // = Clear unused f-seg ram.

     str= uct allocinfo_s *info =3D alloc_find_lowest(&ZoneFSeg);

-    u32 size= =3D info->range_end - info->range_start;

-    memset(m= emremap(info->range_start, size), 0, size);

-    dprintf(= 1, "Space available for UMB: %x-%x, %x-%x\n"

-    &nb= sp;       , RomEnd, base, info->range_star= t, info->range_end);

+    if (= info) {

+    = ;    u32 size =3D info->range_end - info->range_start;=

+    = ;    memset(memremap(info->range_start, size), 0, size);<= o:p>

+    = ;    dprintf(1, "Space available for UMB: %x-%x, %x-%x\= n"

+    = ;            , RomEn= d, base, info->range_start, info->range_end);

+    }

 

     // = Give back unused high ram.

     inf= o =3D alloc_find_lowest(&ZoneHigh);

--

2.19.1

 

--_000_231b2266ae9e41b882d773a8a4c677c5huaweicom_-- --===============2294095467712185558== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org --===============2294095467712185558==--