[edk2-devel] [edk2-redfish-client][PATCH v2 11/11] RedfishFeatureCoreDxe: add check for memory allocation failure

Mike Maslenkin posted 11 patches 2 years, 3 months ago
[edk2-devel] [edk2-redfish-client][PATCH v2 11/11] RedfishFeatureCoreDxe: add check for memory allocation failure
Posted by Mike Maslenkin 2 years, 3 months ago
Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
---
 .../RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c           | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
index f71b12e4b5e0..d9aa6e1a8145 100644
--- a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
+++ b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
@@ -331,6 +331,12 @@ NewInternalInstance (
   }
 
   NewInternalData->NodeName = AllocateZeroPool (StrSize (NodeName));
+  if (NewInternalData->NodeName == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: No memory for NodeName\n", __func__));
+    FreePool (NewInternalData);
+    return EFI_OUT_OF_RESOURCES;
+  }
+
   StrnCpyS (NewInternalData->NodeName, StrLen (NodeName) + 1, (CONST CHAR16 *)NodeName, StrLen (NodeName));
   NewInternalData->SiblingList = NULL;
   NewInternalData->ChildList   = NULL;
-- 
2.32.0 (Apple Git-132)



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110156): https://edk2.groups.io/g/devel/message/110156
Mute This Topic: https://groups.io/mt/102211780/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [edk2-redfish-client][PATCH v2 11/11] RedfishFeatureCoreDxe: add check for memory allocation failure
Posted by Chang, Abner via groups.io 2 years, 3 months ago
[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@amd.com>

> -----Original Message-----
> From: Mike Maslenkin <mike.maslenkin@gmail.com>
> Sent: Friday, October 27, 2023 7:54 AM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; nicklew@nvidia.com;
> igork@ami.com; Mike Maslenkin <mike.maslenkin@gmail.com>
> Subject: [edk2-redfish-client][PATCH v2 11/11] RedfishFeatureCoreDxe: add
> check for memory allocation failure
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
> ---
>  .../RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c           | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
> b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
> index f71b12e4b5e0..d9aa6e1a8145 100644
> --- a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
> +++ b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c
> @@ -331,6 +331,12 @@ NewInternalInstance (
>    }
>
>
>
>    NewInternalData->NodeName = AllocateZeroPool (StrSize (NodeName));
>
> +  if (NewInternalData->NodeName == NULL) {
>
> +    DEBUG ((DEBUG_ERROR, "%a: No memory for NodeName\n", __func__));
>
> +    FreePool (NewInternalData);
>
> +    return EFI_OUT_OF_RESOURCES;
>
> +  }
>
> +
>
>    StrnCpyS (NewInternalData->NodeName, StrLen (NodeName) + 1, (CONST
> CHAR16 *)NodeName, StrLen (NodeName));
>
>    NewInternalData->SiblingList = NULL;
>
>    NewInternalData->ChildList   = NULL;
>
> --
> 2.32.0 (Apple Git-132)



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110169): https://edk2.groups.io/g/devel/message/110169
Mute This Topic: https://groups.io/mt/102211780/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-