]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/HttpDxe: Fix the potential NULL dereference
authorJiaxin Wu <jiaxin.wu@intel.com>
Fri, 23 Dec 2016 03:13:21 +0000 (11:13 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Mon, 26 Dec 2016 08:56:14 +0000 (16:56 +0800)
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Hao A <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg/HttpDxe/HttpProto.c
NetworkPkg/HttpDxe/HttpsSupport.c

index 77aa64a2b99668ef6b65920e6820d3c665615332..d19f73348d4931d3058bf6afbbca03e5bd4aed1e 100644 (file)
@@ -591,10 +591,12 @@ EfiHttpRequest (
 \r
   Status = HttpGenRequestMessage (HttpMsg, FileUrl, &RequestMsg, &RequestMsgSize);\r
 \r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || NULL == RequestMsg) {\r
     goto Error3;\r
   }\r
 \r
+  ASSERT (RequestMsg != NULL);\r
+\r
   //\r
   // Every request we insert a TxToken and a response call would remove the TxToken.\r
   // In cases of PUT/POST, after an initial request-response pair, we would do a\r
index 36c61e2e997adba39f9b02de8fa4c16eac58646b..199d575cf906a0c68f21db24439755f3d49c2ab4 100644 (file)
@@ -1655,6 +1655,8 @@ HttpTcpTransmit (
   UINTN                     UrlSize;\r
   UINTN                     RequestMsgSize;\r
 \r
+  RequestMsg = NULL;\r
+\r
   ValueInItem = (HTTP_TOKEN_WRAP *) Item->Value;\r
   if (ValueInItem->TcpWrap.IsTxDone) {\r
     return EFI_SUCCESS;\r
@@ -1682,10 +1684,12 @@ HttpTcpTransmit (
                  );\r
   FreePool (Url);\r
 \r
-  if (EFI_ERROR (Status)){\r
+  if (EFI_ERROR (Status) || NULL == RequestMsg){\r
     return Status;\r
   }\r
 \r
+  ASSERT (RequestMsg != NULL);\r
+\r
   //\r
   // Transmit the request message.\r
   //\r
index 478a9e0b7b87926a2e5300080e69d2890adf1448..c9e6988968c1895213e1736706d34d983914b484 100644 (file)
@@ -401,33 +401,37 @@ TlsConfigCertificate (
                    NULL
                    );
 
-  if (Status == EFI_BUFFER_TOO_SMALL) {
+  if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {
+    return Status;
+  }
+
+  //
+  // Allocate buffer and read the config variable.
+  //
+  CACert = AllocatePool (CACertSize);
+  if (CACert == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  Status = gRT->GetVariable (
+                  EFI_TLS_CA_CERTIFICATE_VARIABLE,
+                  &gEfiTlsCaCertificateGuid,
+                  NULL,
+                  &CACertSize,
+                  CACert
+                  );
+  if (EFI_ERROR (Status)) {
     //
-    // Allocate buffer and read the config variable.
+    // GetVariable still error or the variable is corrupted.
+    // Fall back to the default value.
     //
-    CACert = AllocatePool (CACertSize);
-    if (CACert == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    Status = gRT->GetVariable (
-                    EFI_TLS_CA_CERTIFICATE_VARIABLE,
-                    &gEfiTlsCaCertificateGuid,
-                    NULL,
-                    &CACertSize,
-                    CACert
-                    );
-    if (EFI_ERROR (Status)) {
-      //
-      // GetVariable still error or the variable is corrupted.
-      // Fall back to the default value.
-      //
-      FreePool (CACert);
+    FreePool (CACert);
 
-      return EFI_NOT_FOUND;
-    }
+    return EFI_NOT_FOUND;
   }
 
+  ASSERT (CACert != NULL);
+
   //
   // Enumerate all data and erasing the target item.
   //
@@ -1037,6 +1041,11 @@ TlsConnectSession (
   //
   PacketOut = NetbufAlloc ((UINT32) BufferOutSize);
   DataOut = NetbufAllocSpace (PacketOut, (UINT32) BufferOutSize, NET_BUF_TAIL);
+  if (DataOut == NULL) {
+    FreePool (BufferOut);
+    return EFI_OUT_OF_RESOURCES;
+  }
+  
   CopyMem (DataOut, BufferOut, BufferOutSize);
   Status = TlsCommonTransmit (HttpInstance, PacketOut);
 
@@ -1107,6 +1116,7 @@ TlsConnectSession (
     FreePool (BufferIn);
 
     if (EFI_ERROR (Status)) {
+      FreePool (BufferOut);
       return Status;
     }
 
@@ -1116,6 +1126,11 @@ TlsConnectSession (
       //
       PacketOut = NetbufAlloc ((UINT32) BufferOutSize);
       DataOut = NetbufAllocSpace (PacketOut, (UINT32) BufferOutSize, NET_BUF_TAIL);
+      if (DataOut == NULL) {
+        FreePool (BufferOut);
+        return EFI_OUT_OF_RESOURCES;
+      }
+      
       CopyMem (DataOut, BufferOut, BufferOutSize);
 
       Status = TlsCommonTransmit (HttpInstance, PacketOut);
@@ -1267,6 +1282,11 @@ TlsCloseSession (
 
   PacketOut = NetbufAlloc ((UINT32) BufferOutSize);
   DataOut = NetbufAllocSpace (PacketOut, (UINT32) BufferOutSize, NET_BUF_TAIL);
+  if (DataOut == NULL) {
+    FreePool (BufferOut);
+    return EFI_OUT_OF_RESOURCES;
+  }
+  
   CopyMem (DataOut, BufferOut, BufferOutSize);
 
   Status = TlsCommonTransmit (HttpInstance, PacketOut);
@@ -1540,6 +1560,11 @@ HttpsReceive (
         if (BufferOutSize != 0) {
           PacketOut = NetbufAlloc ((UINT32)BufferOutSize);
           DataOut = NetbufAllocSpace (PacketOut, (UINT32) BufferOutSize, NET_BUF_TAIL);
+          if (DataOut == NULL) {
+            FreePool (BufferOut);
+            return EFI_OUT_OF_RESOURCES;
+          }
+          
           CopyMem (DataOut, BufferOut, BufferOutSize);
 
           Status = TlsCommonTransmit (HttpInstance, PacketOut);
@@ -1627,6 +1652,11 @@ HttpsReceive (
     if (BufferOutSize != 0) {
       PacketOut = NetbufAlloc ((UINT32) BufferOutSize);
       DataOut = NetbufAllocSpace (PacketOut, (UINT32) BufferOutSize, NET_BUF_TAIL);
+      if (DataOut == NULL) {
+        FreePool (BufferOut);
+        return EFI_OUT_OF_RESOURCES;
+      }
+      
       CopyMem (DataOut, BufferOut, BufferOutSize);
 
       Status = TlsCommonTransmit (HttpInstance, PacketOut);