]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg: Enhance the NULL pointer check before dereference it.
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
index 80e819201ec1b667dbf78d325b380b56df2763b1..50c061743665b4c1511b5a849dca76dca0833029 100644 (file)
@@ -224,6 +224,7 @@ EfiHttpRequest (
   BOOLEAN                       ReConfigure;\r
   CHAR8                         *RequestStr;\r
   CHAR8                         *Url;\r
+  UINTN                         UrlLen;\r
   CHAR16                        *HostNameStr;\r
   HTTP_TOKEN_WRAP               *Wrap;\r
   HTTP_TCP_TOKEN_WRAP           *TcpWrap;\r
@@ -274,7 +275,6 @@ EfiHttpRequest (
     return EFI_ACCESS_DENIED;   \r
   }  \r
 \r
-  Url         = NULL;\r
   HostName    = NULL;\r
   Wrap        = NULL;\r
   HostNameStr = NULL;\r
@@ -283,10 +283,16 @@ EfiHttpRequest (
   //\r
   // Parse the URI of the remote host.\r
   //\r
-  Url = AllocatePool (StrLen (Request->Url) + 1);\r
-  if (Url == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  Url = HttpInstance->Url;\r
+  UrlLen = StrLen (Request->Url) + 1;\r
+  if (UrlLen > HTTP_URL_BUFFER_LEN) {\r
+    Url = AllocateZeroPool (UrlLen);\r
+    if (Url == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    FreePool (HttpInstance->Url);\r
+    HttpInstance->Url = Url;    \r
+  }  \r
 \r
   UnicodeStrToAsciiStr (Request->Url, Url);\r
   UrlParser = NULL;\r
@@ -310,7 +316,7 @@ EfiHttpRequest (
   Configure   = TRUE;\r
   ReConfigure = TRUE;  \r
 \r
-  if (HttpInstance->RemoteHost == NULL && HttpInstance->RemotePort == 0) {\r
+  if (HttpInstance->RemoteHost == NULL) {\r
     //\r
     // Request() is called the first time. \r
     //\r
@@ -347,7 +353,6 @@ EfiHttpRequest (
 \r
         Wrap->TcpWrap.Method = Request->Method;\r
 \r
-        FreePool (Url);\r
         FreePool (HostName);\r
         \r
         //\r
@@ -368,6 +373,7 @@ EfiHttpRequest (
       if (HttpInstance->RemoteHost != NULL) {\r
         FreePool (HttpInstance->RemoteHost);\r
         HttpInstance->RemoteHost = NULL;\r
+        HttpInstance->RemotePort = 0;\r
       }\r
     }\r
   } \r
@@ -480,7 +486,6 @@ EfiHttpRequest (
     goto Error4;\r
   }\r
 \r
-  FreePool (Url);\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -498,6 +503,8 @@ EfiHttpRequest (
     goto Error5;    \r
   }\r
 \r
+  DispatchDpc ();\r
+\r
   return EFI_SUCCESS;\r
 \r
 Error5:\r
@@ -516,12 +523,10 @@ Error2:
   HttpCloseTcp4ConnCloseEvent (HttpInstance);\r
   if (NULL != Wrap->TcpWrap.TxToken.CompletionToken.Event) {\r
     gBS->CloseEvent (Wrap->TcpWrap.TxToken.CompletionToken.Event);\r
+    Wrap->TcpWrap.TxToken.CompletionToken.Event = NULL;\r
   }\r
 \r
 Error1:\r
-  if (Url != NULL) {\r
-    FreePool (Url);\r
-  }\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -757,7 +762,8 @@ HttpBodyParserCallback (
 \r
   @retval EFI_SUCCESS             Allocation succeeded.\r
   @retval EFI_OUT_OF_RESOURCES    Failed to complete the opration due to lack of resources.\r
-  @retval EFI_NOT_READY           Can't find a corresponding TxToken.\r
+  @retval EFI_NOT_READY           Can't find a corresponding TxToken or \r
+                                  the EFI_HTTP_UTILITIES_PROTOCOL is not available.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -953,10 +959,25 @@ HttpResponseWorker (
     CopyMem (HeaderTmp, Tmp, SizeofHeaders);\r
     FreePool (HttpHeaders);\r
     HttpHeaders = HeaderTmp;\r
+\r
+    //\r
+    // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.\r
+    //\r
+    if (mHttpUtilities == NULL) {\r
+      Status = EFI_NOT_READY;\r
+      goto Error;\r
+    }\r
+    \r
     //\r
     // Parse the HTTP header into array of key/value pairs.\r
     //\r
-    Status = HttpUtilitiesParse (HttpHeaders, SizeofHeaders, &HttpMsg->Headers, &HttpMsg->HeaderCount);\r
+    Status = mHttpUtilities->Parse (\r
+                               mHttpUtilities, \r
+                               HttpHeaders, \r
+                               SizeofHeaders, \r
+                               &HttpMsg->Headers, \r
+                               &HttpMsg->HeaderCount\r
+                               );\r
     if (EFI_ERROR (Status)) {\r
       goto Error;\r
     }\r
@@ -1312,6 +1333,7 @@ EfiHttpPoll (
   )\r
 {\r
   HTTP_PROTOCOL                 *HttpInstance;\r
+  EFI_STATUS                    Status;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1328,5 +1350,9 @@ EfiHttpPoll (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  return HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);\r
+  Status = HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);\r
+\r
+  DispatchDpc ();\r
+\r
+  return Status;\r
 }\r