]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Replace ASSERT with error handling in Http boot and IScsi
authorZhang Lubo <lubo.zhang@intel.com>
Tue, 21 Jun 2016 06:40:28 +0000 (14:40 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 23 Jun 2016 01:27:14 +0000 (09:27 +0800)
v2:
*Fix some memory leak issue.

This patch is used to replace ASSERT with error handling in Http boot
Driver and IScsi driver.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-By: Wu Jiaxin <jiaxin.wu@intel.com>
NetworkPkg/HttpBootDxe/HttpBootConfig.c
NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
NetworkPkg/IScsiDxe/IScsiConfig.c
NetworkPkg/IScsiDxe/IScsiDriver.c
NetworkPkg/IScsiDxe/IScsiMisc.c
NetworkPkg/IScsiDxe/IScsiProto.c

index 7ae2ff61f200a4c1d097d5ff2d4c1f70ab721aa9..7c883b8397b00708d58d3d160c18b712b929c324 100644 (file)
@@ -273,7 +273,9 @@ HttpBootFormExtractConfig (
     ConfigRequestHdr = HiiConstructConfigHdr (&gHttpBootConfigGuid, mHttpBootConfigStorageName, CallbackInfo->ChildHandle);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
-    ASSERT (ConfigRequest != NULL);\r
+    if (ConfigRequest == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
     AllocatedRequest = TRUE;\r
     UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
     FreePool (ConfigRequestHdr);\r
@@ -464,7 +466,6 @@ HttpBootFormCallback (
     // Get user input URI string\r
     //\r
     Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);\r
-    ASSERT (Uri != NULL);\r
     if (Uri == NULL) {\r
       return EFI_UNSUPPORTED;\r
     }\r
index 0157095edf821c4b89cd94a1edc205d18ebb5651..9ea421d758ecbe974b9ced885cab355302820d09 100644 (file)
@@ -401,6 +401,7 @@ HttpBootCacheDhcp6Offer (
   @retval EFI_NOT_READY         Only used in the Dhcp6Selecting state. The EFI DHCPv6 Protocol\r
                                 driver will continue to wait for more packets.\r
   @retval EFI_ABORTED           Told the EFI DHCPv6 Protocol driver to abort the current process.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resources.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -451,7 +452,9 @@ HttpBootDhcp6CallBack (
        ASSERT (NewPacket != NULL);\r
        SelectAd   = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;\r
        *NewPacket = AllocateZeroPool (SelectAd->Size);\r
-       ASSERT (*NewPacket != NULL);\r
+       if (*NewPacket == NULL) {\r
+         return EFI_OUT_OF_RESOURCES;\r
+       }\r
        CopyMem (*NewPacket, SelectAd, SelectAd->Size);\r
      }\r
      break;\r
index a82ce231e8db26335d20ef24fde1d60729a229aa..8015e3de53ed7882934a4b5096a4f2182f33e3a9 100644 (file)
@@ -1987,7 +1987,11 @@ IScsiFormExtractConfig (
     ConfigRequestHdr = HiiConstructConfigHdr (&gIScsiConfigGuid, mVendorStorageName, Private->DriverHandle);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
-    ASSERT (ConfigRequest != NULL);\r
+    if (ConfigRequest == NULL) {\r
+      FreePool (IfrNvData);\r
+      FreePool (InitiatorName);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
     AllocatedRequest = TRUE;\r
     UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
     FreePool (ConfigRequestHdr);\r
index 7e7eb39ee2304afac633916ffbf43c1fc51abfb6..c3ab2c92881d6041aceac0329732f3cfee2a6c0c 100644 (file)
@@ -323,6 +323,7 @@ IScsiSupported (
   @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
   @retval EFI_NOT_FOUND         There is no sufficient information to establish\r
                                 the iScsi session.\r
+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory.\r
   @retval EFI_DEVICE_ERROR      Failed to get TCP connection device path.\r
   @retval EFI_ACCESS_DENIED     The protocol could not be removed from the Handle\r
                                 because its interfaces are being used.\r
index 93c0d0c67294f32ef1b0f3c609fed8b6921ecc41..deebf5d9a38751d715440799c7d6cf30a64e6e06 100644 (file)
@@ -1006,6 +1006,7 @@ IScsiDhcpIsConfigured (
 \r
   @retval EFI_SUCCESS            The configuration data is retrieved.\r
   @retval EFI_NOT_FOUND          This iSCSI driver is not configured yet.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1292,7 +1293,9 @@ IScsiGetConfigData (
                                                  mPrivate->PortString,\r
                                                  NULL\r
                                                  );\r
-    ASSERT (AttemptConfigData->AttemptTitleHelpToken != 0);\r
+    if (AttemptConfigData->AttemptTitleHelpToken == 0) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
     //\r
     // Record the attempt in global link list.\r
index 4c4e3c28e7b17e8eead28ea2f18c6c25e552630c..c82290e55ef250d22121321cd3264defc8d5fa7c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of iSCSI protocol based on RFC3720.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -731,7 +731,10 @@ IScsiPrepareLoginReq (
   }\r
 \r
   LoginReq = (ISCSI_LOGIN_REQUEST *) NetbufAllocSpace (Nbuf, sizeof (ISCSI_LOGIN_REQUEST), NET_BUF_TAIL);\r
-  ASSERT (LoginReq != NULL);\r
+  if (LoginReq == NULL) {\r
+    NetbufFree (Nbuf);\r
+    return NULL;\r
+  }\r
   ZeroMem (LoginReq, sizeof (ISCSI_LOGIN_REQUEST));\r
 \r
   //\r
@@ -1245,7 +1248,10 @@ IScsiReceivePdu (
   }\r
 \r
   Header = NetbufAllocSpace (PduHdr, Len, NET_BUF_TAIL);\r
-  ASSERT (Header != NULL);\r
+  if (Header == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
   InsertTailList (NbufList, &PduHdr->List);\r
 \r
   //\r
@@ -2316,7 +2322,10 @@ IScsiNewDataOutPdu (
   InsertTailList (NbufList, &PduHdr->List);\r
 \r
   DataOutHdr  = (ISCSI_SCSI_DATA_OUT *) NetbufAllocSpace (PduHdr, sizeof (ISCSI_SCSI_DATA_OUT), NET_BUF_TAIL);\r
-  ASSERT (DataOutHdr != NULL);\r
+  if (DataOutHdr == NULL) {\r
+    IScsiFreeNbufList (NbufList);\r
+    return NULL;\r
+  }\r
   XferContext = &Tcb->XferContext;\r
 \r
   ZeroMem (DataOutHdr, sizeof (ISCSI_SCSI_DATA_OUT));\r