This patch is used to fix potential assert issue when
connection failed or buffer allocation failed.

Cc: Palmer Thomas <thomas.pal...@hpe.com>
Cc: Samer El-Haj-Mahmoud <smahm...@lenovo.com>
Cc: Long Qin <qin.l...@intel.com>
Cc: Ye Ting <ting...@intel.com>
Cc: Fu Siyuan <siyuan...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin...@intel.com>
---
 NetworkPkg/HttpDxe/HttpsSupport.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpsSupport.c 
b/NetworkPkg/HttpDxe/HttpsSupport.c
index 36f658c..d746972 100644
--- a/NetworkPkg/HttpDxe/HttpsSupport.c
+++ b/NetworkPkg/HttpDxe/HttpsSupport.c
@@ -874,11 +874,14 @@ TlsReceiveOnePdu (
     Status = EFI_OUT_OF_RESOURCES;
     goto ON_EXIT;
   }
 
   Header = NetbufAllocSpace (PduHdr, Len, NET_BUF_TAIL);
-  ASSERT (Header != NULL);
+  if (Header == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ON_EXIT;
+  }
 
   //
   // First step, receive one TLS header.
   //
   Status = TlsCommonReceive (HttpInstance, PduHdr, Timeout);
@@ -899,12 +902,10 @@ TlsReceiveOnePdu (
     InsertTailList (NbufList, &PduHdr->List);
   } else {
     Status = EFI_PROTOCOL_ERROR;
     goto ON_EXIT;
   }
-
-  ASSERT(Header != NULL);
     
   Len = SwapBytes16(RecordHeader.Length);
   if (Len == 0) {
     //
     // No TLS playload.
@@ -1184,11 +1185,13 @@ TlsConnectSession (
     if(HttpInstance->TlsSessionState == EfiTlsSessionError) {  
       return EFI_ABORTED;    
     }
   }
 
-  ASSERT(HttpInstance->TlsSessionState == EfiTlsSessionDataTransferring);
+  if (HttpInstance->TlsSessionState != EfiTlsSessionDataTransferring) {
+    Status = EFI_ABORTED;
+  }
 
   return Status;
 }
 
 /**
@@ -1572,11 +1575,14 @@ HttpsReceive (
     //
     ASSERT (((TLSRecordHeader *) (TempFragment.Bulk))->ContentType == 
TLS_CONTENT_TYPE_APPLICATION_DATA);
     
     BufferInSize = ((TLSRecordHeader *) (TempFragment.Bulk))->Length;
     BufferIn = AllocateZeroPool (BufferInSize);
-    ASSERT (BufferIn != NULL);
+    if (BufferIn == NULL) {
+      Status = EFI_OUT_OF_RESOURCES;
+      return Status;
+    }
 
     CopyMem (BufferIn, TempFragment.Bulk + sizeof (TLSRecordHeader), 
BufferInSize);
 
     //
     // Free the buffer in TempFragment.
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to