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 9A6EF21DFA7BB for ; Tue, 28 Mar 2017 19:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490753867; x=1522289867; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=J4gHCtPYMOe6qKpgIgcGAA9J4B7qOJO5x39H/+f3XqE=; b=cPkeYRM69B2dsBZv1DKJ8WJ5dmonkJ0kE8CiF92Agyf2YMBhkqRXz6nP UwS8kWM4GFJsjPrzzAuec9WPO5iIAw==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2017 19:17:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,239,1486454400"; d="scan'208";a="949240777" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga003.jf.intel.com with ESMTP; 28 Mar 2017 19:17:47 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 28 Mar 2017 19:17:46 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 28 Mar 2017 19:17:46 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.212]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.224]) with mapi id 14.03.0248.002; Wed, 29 Mar 2017 10:17:44 +0800 From: "Zhang, Lubo" To: "Wu, Jiaxin" , "edk2-devel@lists.01.org" CC: "Ye, Ting" , "Fu, Siyuan" Thread-Topic: [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status if URI port is invalid Thread-Index: AQHSpsYWRQyHQARa2UCQOaLu014o06GrFV+Q Date: Wed, 29 Mar 2017 02:17:43 +0000 Message-ID: <7619447B08B8F74DA4FF2A813B79803B39B1365E@shsmsx102.ccr.corp.intel.com> References: <1490597256-16356-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: <1490597256-16356-1-git-send-email-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: Wed, 29 Mar 2017 02:17:47 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Zhang Lubo -----Original Message----- From: Wu, Jiaxin=20 Sent: Monday, March 27, 2017 2:48 PM To: edk2-devel@lists.01.org Cc: Zhang, Lubo ; Ye, Ting ; Fu, S= iyuan ; Wu, Jiaxin Subject: [Patch] MdeModulePkg/DxeHttpLib: Fix the incorrect return status i= f URI port is invalid 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 +++++++++++++++ MdeModu= lePkg/Library/DxeHttpLib/DxeHttpLib.h | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Li= brary/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; =20 if (Url =3D=3D NULL || UrlParser =3D=3D NULL || Port =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 + *Port =3D 0; + Index =3D 0; + Parser =3D (HTTP_URL_PARSER*) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) =3D=3D 0) { return EFI_INVALID_PARAMETER; } @@ -721,12 +725,23 @@ HttpUrlGetPort ( return Status; } =20 PortString[ResultLength] =3D '\0'; =20 + while (Index < ResultLength) { + if (!NET_IS_DIGIT (PortString[Index])) { + return EFI_INVALID_PARAMETER; + } + Index ++; + } + Status =3D AsciiStrDecimalToUintnS (Url + Parser->FieldData[HTTP_URI_FI= ELD_PORT].Offset, (CHAR8 **) NULL, &Data); =20 + if (Data > HTTP_URI_PORT_MAX_NUM || Data < HTTP_URI_PORT_MIN_NUM) { + return EFI_INVALID_PARAMETER; + } + *Port =3D (UINT16) Data; return Status; } =20 /** diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.h b/MdeModulePkg/Li= brary/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. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights=20 + reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
=20 This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e 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 =20 +#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