[edk2] [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status if URI port is invalid

Jiaxin Wu posted 1 patch 7 years ago
Failed in applying to current master (apply log)
MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 15 +++++++++++++++
MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h |  5 ++++-
2 files changed, 19 insertions(+), 1 deletion(-)
[edk2] [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status if URI port is invalid
Posted by Jiaxin Wu 7 years ago
Cc: Zhang Lubo <lubo.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 15 +++++++++++++++
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h |  5 ++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 2ff04ff..8e29213 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -690,18 +690,22 @@ HttpUrlGetPort (
      OUT  UINT16             *Port
   )
 {
   CHAR8         *PortString;
   EFI_STATUS    Status;
+  UINTN         Index;
   UINTN         Data;
   UINT32        ResultLength;
   HTTP_URL_PARSER      *Parser;
 
   if (Url == NULL || UrlParser == NULL || Port == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
+  *Port = 0;
+  Index = 0;
+
   Parser = (HTTP_URL_PARSER*) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {
     return EFI_INVALID_PARAMETER;
   }
@@ -721,12 +725,23 @@ HttpUrlGetPort (
     return Status;
   }
 
   PortString[ResultLength] = '\0';
 
+  while (Index < ResultLength) {
+    if (!NET_IS_DIGIT (PortString[Index])) {
+      return EFI_INVALID_PARAMETER;
+    }
+    Index ++;
+  }
+
   Status =  AsciiStrDecimalToUintnS (Url + Parser->FieldData[HTTP_URI_FIELD_PORT].Offset, (CHAR8 **) NULL, &Data);
 
+  if (Data > HTTP_URI_PORT_MAX_NUM || Data < HTTP_URI_PORT_MIN_NUM) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   *Port = (UINT16) Data;
   return Status;
 }
 
 /**
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h
index 0d0ad3d..5ee0fdc 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h
@@ -1,9 +1,9 @@
 /** @file
 Header file for HttpLib.
 
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -48,10 +48,13 @@ Header file for HttpLib.
 #define   HTTP_URI_FIELD_USERINFO         5
 #define   HTTP_URI_FIELD_HOST             6
 #define   HTTP_URI_FIELD_PORT             7
 #define   HTTP_URI_FIELD_MAX              8
 
+#define   HTTP_URI_PORT_MIN_NUM           0
+#define   HTTP_URI_PORT_MAX_NUM           65535
+
 //
 // Structure to store the parse result of a HTTP URL.
 //
 typedef struct {
   UINT32      Offset;
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status if URI port is invalid
Posted by Zhang, Lubo 7 years ago
Reviewed-by: Zhang Lubo <lubo.zhang@intel.com>

-----Original Message-----
From: Wu, Jiaxin 
Sent: Monday, March 27, 2017 2:48 PM
To: edk2-devel@lists.01.org
Cc: Zhang, Lubo <lubo.zhang@intel.com>; Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status if URI port is invalid

Cc: Zhang Lubo <lubo.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 15 +++++++++++++++  MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h |  5 ++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 2ff04ff..8e29213 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -690,18 +690,22 @@ HttpUrlGetPort (
      OUT  UINT16             *Port
   )
 {
   CHAR8         *PortString;
   EFI_STATUS    Status;
+  UINTN         Index;
   UINTN         Data;
   UINT32        ResultLength;
   HTTP_URL_PARSER      *Parser;
 
   if (Url == NULL || UrlParser == NULL || Port == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
+  *Port = 0;
+  Index = 0;
+
   Parser = (HTTP_URL_PARSER*) UrlParser;
 
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {
     return EFI_INVALID_PARAMETER;
   }
@@ -721,12 +725,23 @@ HttpUrlGetPort (
     return Status;
   }
 
   PortString[ResultLength] = '\0';
 
+  while (Index < ResultLength) {
+    if (!NET_IS_DIGIT (PortString[Index])) {
+      return EFI_INVALID_PARAMETER;
+    }
+    Index ++;
+  }
+
   Status =  AsciiStrDecimalToUintnS (Url + Parser->FieldData[HTTP_URI_FIELD_PORT].Offset, (CHAR8 **) NULL, &Data);
 
+  if (Data > HTTP_URI_PORT_MAX_NUM || Data < HTTP_URI_PORT_MIN_NUM) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   *Port = (UINT16) Data;
   return Status;
 }
 
 /**
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h
index 0d0ad3d..5ee0fdc 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h
@@ -1,9 +1,9 @@
 /** @file
 Header file for HttpLib.
 
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2017, Intel Corporation. All rights 
+ reserved.<BR>
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at @@ -48,10 +48,13 @@ Header file for HttpLib.
 #define   HTTP_URI_FIELD_USERINFO         5
 #define   HTTP_URI_FIELD_HOST             6
 #define   HTTP_URI_FIELD_PORT             7
 #define   HTTP_URI_FIELD_MAX              8
 
+#define   HTTP_URI_PORT_MIN_NUM           0
+#define   HTTP_URI_PORT_MAX_NUM           65535
+
 //
 // Structure to store the parse result of a HTTP URL.
 //
 typedef struct {
   UINT32      Offset;
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel