]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
MdeModulePkg/DxeHttpLib: Handle new #define in HttpMappingToStatusCode
[mirror_edk2.git] / MdeModulePkg / Library / DxeHttpLib / DxeHttpLib.c
index 727cc428f480e815801f587d47742c2ed24080d0..505d5c89e9ab2d0b385d15147c58d8675ddb99be 100644 (file)
@@ -2,7 +2,7 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to parse the HTTP message byte stream.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -396,7 +396,7 @@ HttpParseUrl (
   FoundAt = FALSE;\r
   for (Char = Url; Char < Url + Length; Char++) {\r
     //\r
-    // Update state machine accoring to next char.\r
+    // Update state machine according to next char.\r
     //\r
     State = NetHttpParseUrlChar (*Char, State);\r
 \r
@@ -523,6 +523,7 @@ HttpUrlGetHostName (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Name);\r
     return Status;\r
   }\r
 \r
@@ -582,6 +583,7 @@ HttpUrlGetIp4 (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Ip4String);\r
     return Status;\r
   }\r
 \r
@@ -657,6 +659,7 @@ HttpUrlGetIp6 (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Ip6String);\r
     return Status;\r
   }\r
   \r
@@ -692,6 +695,8 @@ HttpUrlGetPort (
 {\r
   CHAR8         *PortString;\r
   EFI_STATUS    Status;\r
+  UINTN         Index;\r
+  UINTN         Data;\r
   UINT32        ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
 \r
@@ -699,6 +704,9 @@ HttpUrlGetPort (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  *Port = 0;\r
+  Index = 0;\r
+\r
   Parser = (HTTP_URL_PARSER*) UrlParser;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {\r
@@ -717,13 +725,31 @@ HttpUrlGetPort (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto ON_EXIT;\r
   }\r
 \r
   PortString[ResultLength] = '\0';\r
-  *Port = (UINT16) AsciiStrDecimalToUintn (Url + Parser->FieldData[HTTP_URI_FIELD_PORT].Offset);\r
 \r
-  return  EFI_SUCCESS;\r
+  while (Index < ResultLength) {\r
+    if (!NET_IS_DIGIT (PortString[Index])) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto ON_EXIT;\r
+    }\r
+    Index ++;\r
+  }\r
+\r
+  Status =  AsciiStrDecimalToUintnS (Url + Parser->FieldData[HTTP_URI_FIELD_PORT].Offset, (CHAR8 **) NULL, &Data);\r
+\r
+  if (Data > HTTP_URI_PORT_MAX_NUM) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  *Port = (UINT16) Data;\r
+\r
+ON_EXIT:\r
+  FreePool (PortString);\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -777,6 +803,7 @@ HttpUrlGetPath (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (PathStr);\r
     return Status;\r
   }\r
 \r
@@ -932,8 +959,7 @@ HttpIoParseContentLengthHeader (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  *ContentLength = AsciiStrDecimalToUintn (Header->FieldValue);\r
-  return EFI_SUCCESS;\r
+  return AsciiStrDecimalToUintnS (Header->FieldValue, (CHAR8 **) NULL, ContentLength);\r
 }\r
 \r
 /**\r
@@ -1430,10 +1456,10 @@ HttpFreeMsgParser (
 \r
 \r
 /**\r
-  Get the next string, which is distinguished by specified seperator.\r
+  Get the next string, which is distinguished by specified separator.\r
 \r
   @param[in]  String             Pointer to the string.\r
-  @param[in]  Seperator          Specified seperator used to distinguish where is the beginning\r
+  @param[in]  Separator          Specified separator used to distinguish where is the beginning\r
                                  of next string.\r
 \r
   @return     Pointer to the next string.\r
@@ -1444,7 +1470,7 @@ CHAR8 *
 EFIAPI\r
 AsciiStrGetNextToken (\r
   IN CONST CHAR8 *String,\r
-  IN       CHAR8 Seperator\r
+  IN       CHAR8 Separator\r
   )\r
 {\r
   CONST CHAR8 *Token;\r
@@ -1454,7 +1480,7 @@ AsciiStrGetNextToken (
     if (*Token == 0) {\r
       return NULL;\r
     }\r
-    if (*Token == Seperator) {\r
+    if (*Token == Separator) {\r
       return (CHAR8 *)(Token + 1);\r
     }\r
     Token++;\r
@@ -1917,6 +1943,8 @@ HttpMappingToStatusCode (
     return HTTP_STATUS_305_USE_PROXY;\r
   case 307:\r
     return HTTP_STATUS_307_TEMPORARY_REDIRECT;\r
+  case 308:\r
+    return HTTP_STATUS_308_PERMANENT_REDIRECT;\r
   case 400:\r
     return HTTP_STATUS_400_BAD_REQUEST;\r
   case 401:\r