]> 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 4bd4ac884fdcffdcbe303d998c35178d70202fe9..50c061743665b4c1511b5a849dca76dca0833029 100644 (file)
@@ -224,10 +224,12 @@ 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
-\r
+  CHAR8                         *FileUrl;\r
+  \r
   if ((This == NULL) || (Token == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -273,7 +275,6 @@ EfiHttpRequest (
     return EFI_ACCESS_DENIED;   \r
   }  \r
 \r
-  Url         = NULL;\r
   HostName    = NULL;\r
   Wrap        = NULL;\r
   HostNameStr = NULL;\r
@@ -282,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
@@ -309,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
@@ -346,7 +353,6 @@ EfiHttpRequest (
 \r
         Wrap->TcpWrap.Method = Request->Method;\r
 \r
-        FreePool (Url);\r
         FreePool (HostName);\r
         \r
         //\r
@@ -367,6 +373,7 @@ EfiHttpRequest (
       if (HttpInstance->RemoteHost != NULL) {\r
         FreePool (HttpInstance->RemoteHost);\r
         HttpInstance->RemoteHost = NULL;\r
+        HttpInstance->RemotePort = 0;\r
       }\r
     }\r
   } \r
@@ -450,7 +457,25 @@ EfiHttpRequest (
   //\r
   // Create request message.\r
   //\r
-  RequestStr = HttpGenRequestString (HttpInstance, HttpMsg, Url);\r
+  FileUrl = Url;\r
+  if (*FileUrl != '/') {\r
+    //\r
+    // Convert the absolute-URI to the absolute-path\r
+    //\r
+    while (*FileUrl != ':') {\r
+      FileUrl++;\r
+    }\r
+    if ((*(FileUrl+1) == '/') && (*(FileUrl+2) == '/')) {\r
+      FileUrl += 3;\r
+      while (*FileUrl != '/') {\r
+        FileUrl++;\r
+      }\r
+    } else {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto Error3;\r
+    }\r
+  }\r
+  RequestStr = HttpGenRequestString (HttpInstance, HttpMsg, FileUrl);\r
   if (RequestStr == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Error3;\r
@@ -461,7 +486,6 @@ EfiHttpRequest (
     goto Error4;\r
   }\r
 \r
-  FreePool (Url);\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -479,6 +503,8 @@ EfiHttpRequest (
     goto Error5;    \r
   }\r
 \r
+  DispatchDpc ();\r
+\r
   return EFI_SUCCESS;\r
 \r
 Error5:\r
@@ -497,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
@@ -738,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
@@ -766,6 +791,10 @@ HttpResponseWorker (
   HTTP_TOKEN_WRAP               *ValueInItem;\r
   UINTN                         HdrLen;\r
 \r
+  if (Wrap == NULL || Wrap->HttpInstance == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
   HttpInstance = Wrap->HttpInstance;\r
   Token = Wrap->HttpToken;\r
 \r
@@ -930,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
@@ -1289,6 +1333,7 @@ EfiHttpPoll (
   )\r
 {\r
   HTTP_PROTOCOL                 *HttpInstance;\r
+  EFI_STATUS                    Status;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1305,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