* [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue
@ 2022-10-29 3:59 Chang, Abner
2022-10-29 7:50 ` [edk2-devel] " Nickle Wang
0 siblings, 1 reply; 2+ messages in thread
From: Chang, Abner @ 2022-10-29 3:59 UTC (permalink / raw)
To: devel; +Cc: Nickle Wang, Igor Kulchytskyy
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 | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
index 1293ddd633c..1616b5134bc 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
@@ -261,6 +261,7 @@ Tcp6GetSubnetInfo (
Tcp6 = (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
+ ZeroMem ((VOID *)&IpModedata, sizeof (EFI_IP6_MODE_DATA));
Status = Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __FUNCTION__));
@@ -282,12 +283,15 @@ Tcp6GetSubnetInfo (
}
Instance->SubnetAddrInfoIPv6Number = IpModedata.AddressCount;
- CopyMem (
- (VOID *)Instance->SubnetAddrInfoIPv6,
- (VOID *)&IpModedata.AddressList,
- IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO)
- );
- FreePool (IpModedata.AddressList);
+ if (IpModedata.AddressCount != 0 && IpModedata.AddressList != 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue
2022-10-29 3:59 [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue Chang, Abner
@ 2022-10-29 7:50 ` Nickle Wang
0 siblings, 0 replies; 2+ messages in thread
From: Nickle Wang @ 2022-10-29 7:50 UTC (permalink / raw)
To: devel@edk2.groups.io, abner.chang@amd.com; +Cc: Nickle Wang, Igor Kulchytskyy
[-- Attachment #1: Type: text/plain, Size: 2223 bytes --]
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Chang, Abner via groups.io <abner.chang=amd.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@ami.com>
Subject: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue
External email: Use caution opening links or attachments
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 | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
index 1293ddd633c..1616b5134bc 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
@@ -261,6 +261,7 @@ Tcp6GetSubnetInfo (
Tcp6 = (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
+ ZeroMem ((VOID *)&IpModedata, sizeof (EFI_IP6_MODE_DATA));
Status = Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __FUNCTION__));
@@ -282,12 +283,15 @@ Tcp6GetSubnetInfo (
}
Instance->SubnetAddrInfoIPv6Number = IpModedata.AddressCount;
- CopyMem (
- (VOID *)Instance->SubnetAddrInfoIPv6,
- (VOID *)&IpModedata.AddressList,
- IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO)
- );
- FreePool (IpModedata.AddressList);
+ if (IpModedata.AddressCount != 0 && IpModedata.AddressList != 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
[-- Attachment #2: Type: text/html, Size: 4173 bytes --]
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-29 7:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-29 3:59 [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue Chang, Abner
2022-10-29 7:50 ` [edk2-devel] " Nickle Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox