From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.53]) by mx.groups.io with SMTP id smtpd.web08.1382.1667029863208270857 for ; Sat, 29 Oct 2022 00:51:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=RRfg8FFS; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.220.53, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ipLJ4fMzmLDWPKdLBQtPmR3POgjsE5jXQ9W5Iq+9G6giof+Zpt/4jKu2ALZbRl2zsQb5aRhi6W2wjCoix9v5lcaQ53VFv+9ZRuLwewrcVJi9yl5kR8l6EIURA2Q0EJ1i2W7kgN2j/Y6oDfGirvYZH6Kikn0jRJVk1nF4zHNHWZkfU08ZAfPQoVWN4gXqAKVHuIYz939Ne9ohpehS/WTBRLLHmg9j3F363YLfJCqj7dGmvJXg4PfQxjaZvCLKVMHbtH3hC2GMhF8x+ruRjHl2vkAIf3T6by24M6I7GCItUdIpJMwBvqgJVwWyUBAV1zHRYwZxMZOXX4b+aArweZ4qaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dTeyMpFsytkGvPSUGGgdHQQhpKdTqRbWiB54Kq+dBaM=; b=AzS2/bj+l83xnRYzUByB/mlLglCCaeVTrrY1YfNCjAXg3C7bU4mpRIJqUFbmnfitF1vM8x6j7BP0dwjZhUg1OpHqUSYJmP17iz6+tbwTcDprZ+MMax5ELNasgCL3HdwDK0hZ5zEyFdf4a2GXBTDu38dcfwTnAvf/YZlb4LSPXylpheQvoAeeV595ABYSwzwwtm7qZNPpUyLfRjxlPanQVsEp7aKv2SPF5gCJvgOPUm2YsoW/7KQ8sBPlWKb//RRjaQJ/tRfoClIxJIytJDDKCjbYkdcihoK6TtBWiQlbf0zwp7ra1+whi2rgDk+Y/WdT0REO/HZNecp1ZnqBOKrIaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dTeyMpFsytkGvPSUGGgdHQQhpKdTqRbWiB54Kq+dBaM=; b=RRfg8FFSi+5jQraDYiKth423oKzjQQUqBnufWT+W+wJfjn0s4Vt5LwQWK+8sc1/F3oxeRxmYnfCi0h/XAsP42Otb70e5QCSUkZxb/frcsy5Q0x8EUdOXgBNgx1WqAEdrtEiXlXoyAFgc14VbLpXJi14shZ0jRiMdz1vy05escbpL5vBuQvDsXPtu0jNigwiU6lr6m2DA0d1GXs/+yibmmXwyFIp6nUUZS3+GBXEg2vfxF6PeLz0iXDn1S7qiDP9CFQBNc4MX1IDQeOKiOPsZLAUATm5msc5UcfXKG69DPa5UuhHluhUA5rSsLK9hHxVXumqpAX6+R7Qf2NWBpIP30A== Received: from MW4PR12MB7031.namprd12.prod.outlook.com (2603:10b6:303:1ef::6) by PH8PR12MB6914.namprd12.prod.outlook.com (2603:10b6:510:1cb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.28; Sat, 29 Oct 2022 07:50:58 +0000 Received: from MW4PR12MB7031.namprd12.prod.outlook.com ([fe80::7fe8:da93:95dc:6657]) by MW4PR12MB7031.namprd12.prod.outlook.com ([fe80::7fe8:da93:95dc:6657%8]) with mapi id 15.20.5769.015; Sat, 29 Oct 2022 07:50:58 +0000 From: "Nickle Wang" To: "devel@edk2.groups.io" , "abner.chang@amd.com" CC: Nickle Wang , Igor Kulchytskyy Subject: Re: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue Thread-Topic: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue Thread-Index: AQHY60rhQr2B8Y7GykqSmO/ugmoKfa4k/6b3 Date: Sat, 29 Oct 2022 07:50:58 +0000 Message-ID: References: <20221029035911.651-1-abner.chang@amd.com> In-Reply-To: <20221029035911.651-1-abner.chang@amd.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR12MB7031:EE_|PH8PR12MB6914:EE_ x-ms-office365-filtering-correlation-id: 45961e27-ac72-4596-fbe0-08dab9825131 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: TJoG2z4bmHdIW5sz08Rx2/fxcPUoT6M1BlidtD2lKph88imXl8ZKKBR/4vGtHrHVgK5oovnscYJyN/qcx8gCWCblBzIrAuwCUTGJJ1rL2PgeE9fGWJH4Knh+FHy3Z+H/t5S6ESaOewaDqoICtYzjHJJ6YdMayktugc4A9ES/i45rJgZTV2AKh703o8v62lj5nEGNYKPRMLKM+uoY0/ngHsorSvKiPYBy6FLpxrGlkpJT/vC3h4TJRnQ0PQXe3MVCczspjBzgeKNKamj1HGFBSyek66yvdLRyn9RowR0z8prcSo8ahNHNcjLCVfFjrcrBHxbr1spWiSLqb+S29lCdEi08FfeWo9i8EbHfJKXFvoNbT0MwO63hQPVaAtkOmqUzeve63FDoRl+05g0Ozid0Br8gsiKJ0327y7cXpdNn/OFy3zOm23I5wjc7M3g7ilCGparkvovryu3Z8BiDDeavXFVI78d8zkqsf3xKzegfpSfYFyVcQ2wEKwUono3JS3ldIJ7BGY0nYUkv96krIiJn76nrYmEyhbuhAM1ji7MsPR8SXdADhxO3b71+0DnlP6WX+d2e3AoY7QqB3iAl2cr7QTt/Gs7FibamUPXQO8ajt5eTYSD7URlNTxfZ7kih2MIIWbhv7169GKTsibmkejCuAzynhzTZOWT/FJ2ti3MZddmBB/j3wOJoq5xuPHLLycf/m20IhEOwtMPd9h2NJS1c57EpOcrbVqc26tbPYI1GZ6+lwpduUJRikrBzizEcfFZrCZXAUoNlEFsNxIAymzExxJjPifcqq/rNvukhbKetxn4= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR12MB7031.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(376002)(346002)(136003)(396003)(39860400002)(451199015)(478600001)(966005)(19627405001)(6506007)(9686003)(53546011)(66899015)(38070700005)(64756008)(122000001)(66446008)(166002)(66556008)(66476007)(4326008)(86362001)(38100700002)(41300700001)(8676002)(186003)(7696005)(71200400001)(8936002)(33656002)(66946007)(76116006)(110136005)(5660300002)(91956017)(55016003)(2906002)(54906003)(83380400001)(52536014)(316002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?6JF9rNdzF+5zQfACPfDNzHjjbiajom/hnScWl9iUgkS0mGF27XwaZxMttKGo?= =?us-ascii?Q?CYmEdg0hUxKI8UA0jAX5wKW3I+944wQWId4Tdl8tLwDwkR2HBq/5dgHuXilH?= =?us-ascii?Q?3Ag9KFO6N7HMWf9d7m9uiaVmuOm8N70/boPY3HPDuR7CN6Pcdd570B4Q21w0?= =?us-ascii?Q?fIMdQFUXZNQ1PeCT+g2GDfkM68u+Gmbl8UEW8RpHl2T4tpdTapEH820FoErC?= =?us-ascii?Q?AIR/uzF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KS+WVi4yRN4sbLz67Hzb?= =?us-ascii?Q?hRr5iBeS+ZNSGoicr9zLQamT7w8e/ITS26ZZS1Oci4apFUcv12BDwYTOi1GP?= =?us-ascii?Q?Q6LreGl1RVRZNlmlXZ0bBCkkiFPoGclqWGlwzzHqrIjc6D9AI2Hh7R4AC1vV?= =?us-ascii?Q?L+Utr0yYWap54tdjH/BBJlG/zNrMtMZOfYK5qK/GUuC+dc7l2vbbNvItLhw/?= =?us-ascii?Q?hKp+XZxsCzO8p2Ply6KH/NfviyVwclXeqN+fCea4eUIcSOpeVWf9wEBjI3jw?= =?us-ascii?Q?8dhi9c6xqIi19BHxNTCvUhte2m3JwqbM4UJz+vmDCkqZ9lpOG0HRz0ap7pyg?= =?us-ascii?Q?5AwMX6r8Bl3ZSziUvLl1UVXOboewmKl6aGVzILcn8m05O98Ne5wVB79UIhLB?= =?us-ascii?Q?aUiL/eHDZx2dUUxC7OWusa3Lpzh9TI267GovgCBZCugJWwMX9PxfBEtYprE5?= =?us-ascii?Q?HLcx8Pl7deLerZxnKdmQyV0IsrvZB+7kg3WjGrEXFdEn0aGZU3oKKgeZpojY?= =?us-ascii?Q?50uw3zyRVFX8nKzvfCfhWrPv9o/FImLExXuj65b8wG9H?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB7031.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45961e27-ac72-4596-fbe0-08dab9825131 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2022 07:50:58.4995 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: J4nNmBLUSqXdu9Wj8zR7GfGg+kG/TDVib3WTw2lshi3pNZdCI4HSoxDagbVQtdz2Z58gSRjlN/r7vEbyLTy/uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6914 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MW4PR12MB70310DA7DE30EBC1B087E5E8D9359MW4PR12MB7031namp_" --_000_MW4PR12MB70310DA7DE30EBC1B087E5E8D9359MW4PR12MB7031namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Nickle Wang ________________________________ From: devel@edk2.groups.io on behalf of Chang, Abner= via groups.io Sent: Saturday, October 29, 2022 11:59 AM To: devel@edk2.groups.io Cc: Nickle Wang ; Igor Kulchytskyy Subject: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory fre= e issue External email: Use caution opening links or attachments From: Abner Chang Check the memory block pointer before freeing it. Cc: Nickle Wang Cc: Igor Kulchytskyy Signed-off-by: Abner Chang --- .../RedfishDiscoverDxe/RedfishDiscoverDxe.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPk= g/RedfishDiscoverDxe/RedfishDiscoverDxe.c index 1293ddd633c..1616b5134bc 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c @@ -261,6 +261,7 @@ Tcp6GetSubnetInfo ( Tcp6 =3D (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.Net= workProtocolInterface; + ZeroMem ((VOID *)&IpModedata, sizeof (EFI_IP6_MODE_DATA)); Status =3D Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL)= ; if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __FUN= CTION__)); @@ -282,12 +283,15 @@ Tcp6GetSubnetInfo ( } Instance->SubnetAddrInfoIPv6Number =3D IpModedata.AddressCount; - CopyMem ( - (VOID *)Instance->SubnetAddrInfoIPv6, - (VOID *)&IpModedata.AddressList, - IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO) - ); - FreePool (IpModedata.AddressList); + if (IpModedata.AddressCount !=3D 0 && IpModedata.AddressList !=3D NULL) = { + CopyMem ( + (VOID *)Instance->SubnetAddrInfoIPv6, + (VOID *)&IpModedata.AddressList, + IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO) + ); + FreePool(IpModedata.AddressList); + } + return EFI_SUCCESS; } -- 2.37.1.windows.1 --_000_MW4PR12MB70310DA7DE30EBC1B087E5E8D9359MW4PR12MB7031namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Reviewed-by: Nickle Wang <nicklew@nvidia.com>

From: devel@edk2.groups.io = <devel@edk2.groups.io> on behalf of Chang, Abner via groups.io <ab= ner.chang=3Damd.com@groups.io>
Sent: Saturday, October 29, 2022 11:59 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Nickle Wang <nickle@csie.io>; Igor Kulchytskyy <igork@a= mi.com>
Subject: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix mem= ory free issue
 
External email: Use caution opening links or attac= hments


From: Abner Chang <abner.chang@amd.com>

Check the memory block pointer before freeing it.

Cc: Nickle Wang <nickle@csie.io>
Cc: Igor Kulchytskyy <igork@ami.com>
Signed-off-by: Abner Chang <abner.chang@amd.com>
---
 .../RedfishDiscoverDxe/RedfishDiscoverDxe.c    &n= bsp; | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPk= g/RedfishDiscoverDxe/RedfishDiscoverDxe.c
index 1293ddd633c..1616b5134bc 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
@@ -261,6 +261,7 @@ Tcp6GetSubnetInfo (

   Tcp6 =3D (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfacePro= tocolInfo.NetworkProtocolInterface;

+  ZeroMem ((VOID *)&IpModedata, sizeof (EFI_IP6_MODE_DATA));
   Status =3D Tcp6->GetModeData (Tcp6, NULL, NULL, &IpMode= data, NULL, NULL);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode d= ata information\n", __FUNCTION__));
@@ -282,12 +283,15 @@ Tcp6GetSubnetInfo (
   }

   Instance->SubnetAddrInfoIPv6Number =3D IpModedata.AddressCo= unt;
-  CopyMem (
-    (VOID *)Instance->SubnetAddrInfoIPv6,
-    (VOID *)&IpModedata.AddressList,
-    IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO)=
-    );
-  FreePool (IpModedata.AddressList);
+  if (IpModedata.AddressCount !=3D 0 && IpModedata.AddressLis= t !=3D NULL) {
+    CopyMem (
+      (VOID *)Instance->SubnetAddrInfoIPv6, +      (VOID *)&IpModedata.AddressList,
+      IpModedata.AddressCount * sizeof (EFI_IP6_A= DDRESS_INFO)
+      );
+    FreePool(IpModedata.AddressList);
+  }
+
   return EFI_SUCCESS;
 }

--
2.37.1.windows.1






--_000_MW4PR12MB70310DA7DE30EBC1B087E5E8D9359MW4PR12MB7031namp_--