]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
MdeModulePkg: Fix potential memory leaks in DxeHttpLib.
[mirror_edk2.git] / MdeModulePkg / Library / DxeHttpLib / DxeHttpLib.c
index 2ff04ffad3ac1b4976c20e1f18a9c12a041f14bd..292923875f0707430e55245eed88c50499dda0de 100644 (file)
@@ -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,7 @@ HttpUrlGetPort (
 {\r
   CHAR8         *PortString;\r
   EFI_STATUS    Status;\r
+  UINTN         Index;\r
   UINTN         Data;\r
   UINT32        ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
@@ -700,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
@@ -718,14 +725,30 @@ HttpUrlGetPort (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto ON_EXIT;\r
   }\r
 \r
   PortString[ResultLength] = '\0';\r
 \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
@@ -780,6 +803,7 @@ HttpUrlGetPath (
              &ResultLength\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (PathStr);\r
     return Status;\r
   }\r
 \r