From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8E4F7208F79D8 for ; Sun, 26 Mar 2017 23:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490597259; x=1522133259; h=from:to:cc:subject:date:message-id; bh=WIzB06vK1MN+WrS1kD6KtrcnbBPjiRcdPYKWW8eCVfU=; b=TTANOhvCwF7XSwTiifAWy5rT2chchkejCj1pHu66UIHZ2bmQaUiuF/0N L00BjMoxkrs3j3rdjXMIHiJLLa+7Xw==; Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Mar 2017 23:47:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,229,1486454400"; d="scan'208";a="240618993" Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.197.54]) by fmsmga004.fm.intel.com with ESMTP; 26 Mar 2017 23:47:37 -0700 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Zhang Lubo , Ye Ting , Fu Siyuan , Wu Jiaxin Date: Mon, 27 Mar 2017 14:47:36 +0800 Message-Id: <1490597256-16356-1-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status if URI port is invalid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2017 06:47:39 -0000 Cc: Zhang Lubo Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- 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.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
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