summaryrefslogtreecommitdiffstats
path: root/NetworkPkg
diff options
context:
space:
mode:
authorZhang Lubo <lubo.zhang@intel.com>2016-06-21 14:40:28 +0800
committerJiaxin Wu <jiaxin.wu@intel.com>2016-06-23 09:27:14 +0800
commit7c275b3cde5fdc3cf6fac068c52455927d09c1c1 (patch)
tree89f56e3ba6f93ceb5081d062be7430ef7acce000 /NetworkPkg
parent3460c75dfe951c50d1d16eb2bb54b4790d49a91d (diff)
downloadedk2-7c275b3cde5fdc3cf6fac068c52455927d09c1c1.tar.gz
edk2-7c275b3cde5fdc3cf6fac068c52455927d09c1c1.tar.bz2
edk2-7c275b3cde5fdc3cf6fac068c52455927d09c1c1.zip
NetworkPkg: Replace ASSERT with error handling in Http boot and IScsi
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>
Diffstat (limited to 'NetworkPkg')
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootConfig.c5
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootDhcp6.c5
-rw-r--r--NetworkPkg/IScsiDxe/IScsiConfig.c6
-rw-r--r--NetworkPkg/IScsiDxe/IScsiDriver.c1
-rw-r--r--NetworkPkg/IScsiDxe/IScsiMisc.c5
-rw-r--r--NetworkPkg/IScsiDxe/IScsiProto.c17
6 files changed, 30 insertions, 9 deletions
diff --git a/NetworkPkg/HttpBootDxe/HttpBootConfig.c b/NetworkPkg/HttpBootDxe/HttpBootConfig.c
index 7ae2ff61f2..7c883b8397 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootConfig.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootConfig.c
@@ -273,7 +273,9 @@ HttpBootFormExtractConfig (
ConfigRequestHdr = HiiConstructConfigHdr (&gHttpBootConfigGuid, mHttpBootConfigStorageName, CallbackInfo->ChildHandle);
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequest == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
@@ -464,7 +466,6 @@ HttpBootFormCallback (
// Get user input URI string
//
Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);
- ASSERT (Uri != NULL);
if (Uri == NULL) {
return EFI_UNSUPPORTED;
}
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c b/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
index 0157095edf..9ea421d758 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
@@ -401,6 +401,7 @@ HttpBootCacheDhcp6Offer (
@retval EFI_NOT_READY Only used in the Dhcp6Selecting state. The EFI DHCPv6 Protocol
driver will continue to wait for more packets.
@retval EFI_ABORTED Told the EFI DHCPv6 Protocol driver to abort the current process.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources.
**/
EFI_STATUS
@@ -451,7 +452,9 @@ HttpBootDhcp6CallBack (
ASSERT (NewPacket != NULL);
SelectAd = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;
*NewPacket = AllocateZeroPool (SelectAd->Size);
- ASSERT (*NewPacket != NULL);
+ if (*NewPacket == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
CopyMem (*NewPacket, SelectAd, SelectAd->Size);
}
break;
diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c
index a82ce231e8..8015e3de53 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -1987,7 +1987,11 @@ IScsiFormExtractConfig (
ConfigRequestHdr = HiiConstructConfigHdr (&gIScsiConfigGuid, mVendorStorageName, Private->DriverHandle);
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequest == NULL) {
+ FreePool (IfrNvData);
+ FreePool (InitiatorName);
+ return EFI_OUT_OF_RESOURCES;
+ }
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.c b/NetworkPkg/IScsiDxe/IScsiDriver.c
index 7e7eb39ee2..c3ab2c9288 100644
--- a/NetworkPkg/IScsiDxe/IScsiDriver.c
+++ b/NetworkPkg/IScsiDxe/IScsiDriver.c
@@ -323,6 +323,7 @@ IScsiSupported (
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
@retval EFI_NOT_FOUND There is no sufficient information to establish
the iScsi session.
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
@retval EFI_DEVICE_ERROR Failed to get TCP connection device path.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the Handle
because its interfaces are being used.
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
index 93c0d0c672..deebf5d9a3 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
@@ -1006,6 +1006,7 @@ IScsiDhcpIsConfigured (
@retval EFI_SUCCESS The configuration data is retrieved.
@retval EFI_NOT_FOUND This iSCSI driver is not configured yet.
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
**/
EFI_STATUS
@@ -1292,7 +1293,9 @@ IScsiGetConfigData (
mPrivate->PortString,
NULL
);
- ASSERT (AttemptConfigData->AttemptTitleHelpToken != 0);
+ if (AttemptConfigData->AttemptTitleHelpToken == 0) {
+ return EFI_OUT_OF_RESOURCES;
+ }
//
// Record the attempt in global link list.
diff --git a/NetworkPkg/IScsiDxe/IScsiProto.c b/NetworkPkg/IScsiDxe/IScsiProto.c
index 4c4e3c28e7..c82290e55e 100644
--- a/NetworkPkg/IScsiDxe/IScsiProto.c
+++ b/NetworkPkg/IScsiDxe/IScsiProto.c
@@ -1,7 +1,7 @@
/** @file
The implementation of iSCSI protocol based on RFC3720.
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -731,7 +731,10 @@ IScsiPrepareLoginReq (
}
LoginReq = (ISCSI_LOGIN_REQUEST *) NetbufAllocSpace (Nbuf, sizeof (ISCSI_LOGIN_REQUEST), NET_BUF_TAIL);
- ASSERT (LoginReq != NULL);
+ if (LoginReq == NULL) {
+ NetbufFree (Nbuf);
+ return NULL;
+ }
ZeroMem (LoginReq, sizeof (ISCSI_LOGIN_REQUEST));
//
@@ -1245,7 +1248,10 @@ IScsiReceivePdu (
}
Header = NetbufAllocSpace (PduHdr, Len, NET_BUF_TAIL);
- ASSERT (Header != NULL);
+ if (Header == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ON_EXIT;
+ }
InsertTailList (NbufList, &PduHdr->List);
//
@@ -2316,7 +2322,10 @@ IScsiNewDataOutPdu (
InsertTailList (NbufList, &PduHdr->List);
DataOutHdr = (ISCSI_SCSI_DATA_OUT *) NetbufAllocSpace (PduHdr, sizeof (ISCSI_SCSI_DATA_OUT), NET_BUF_TAIL);
- ASSERT (DataOutHdr != NULL);
+ if (DataOutHdr == NULL) {
+ IScsiFreeNbufList (NbufList);
+ return NULL;
+ }
XferContext = &Tcb->XferContext;
ZeroMem (DataOutHdr, sizeof (ISCSI_SCSI_DATA_OUT));