From nobody Sun May 5 23:24:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514252038016292.1597643355709; Mon, 25 Dec 2017 17:33:58 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 179AE222447B8; Mon, 25 Dec 2017 17:29:03 -0800 (PST) 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 EF65122225C1A for ; Mon, 25 Dec 2017 17:29:00 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Dec 2017 17:33:54 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.165]) by orsmga002.jf.intel.com with ESMTP; 25 Dec 2017 17:33:53 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,457,1508828400"; d="scan'208";a="21327527" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 26 Dec 2017 09:33:45 +0800 Message-Id: <1514252029-12720-2-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> References: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 1/5] MdeModulePkg/DxeHttpLib: Add boundary condition check. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch is to add the boundary condition check to make sure the accessed buffer is valid. Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 39 ++++++++++++++++++++++++= ---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Li= brary/DxeHttpLib/DxeHttpLib.c index caddbb7..4d353d7 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -33,11 +33,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. @retval EFI_SUCCESS Successfully decoded the URI. @retval EFI_INVALID_PARAMETER Buffer is not a valid percent-encoded str= ing. =20 **/ EFI_STATUS -EFIAPI UriPercentDecode ( IN CHAR8 *Buffer, IN UINT32 BufferLength, OUT CHAR8 *ResultBuffer, OUT UINT32 *ResultLength @@ -54,11 +53,11 @@ UriPercentDecode ( Index =3D 0; Offset =3D 0; HexStr[2] =3D '\0'; while (Index < BufferLength) { if (Buffer[Index] =3D=3D '%') { - if (!NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[I= ndex+2])) { + if (Index + 1 >=3D BufferLength || Index + 2 >=3D BufferLength || !N= ET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2])) { return EFI_INVALID_PARAMETER; } HexStr[0] =3D Buffer[Index+1]; HexStr[1] =3D Buffer[Index+2]; ResultBuffer[Offset] =3D (CHAR8) AsciiStrHexToUintn (HexStr); @@ -1556,20 +1555,31 @@ HttpGetFieldNameAndValue ( ) { CHAR8 *FieldNameStr; CHAR8 *FieldValueStr; CHAR8 *StrPtr; + CHAR8 *EndofHeader; =20 if (String =3D=3D NULL || FieldName =3D=3D NULL || FieldValue =3D=3D NUL= L) { return NULL; } =20 *FieldName =3D NULL; *FieldValue =3D NULL; FieldNameStr =3D NULL; FieldValueStr =3D NULL; StrPtr =3D NULL; + EndofHeader =3D NULL; + + + // + // Check whether the raw HTTP header string is valid or not. + // + EndofHeader =3D AsciiStrStr (String, "\r\n\r\n"); + if (EndofHeader =3D=3D NULL) { + return NULL; + } =20 // // Each header field consists of a name followed by a colon (":") and th= e field value. // FieldNameStr =3D String; @@ -1583,17 +1593,36 @@ HttpGetFieldNameAndValue ( // *(FieldValueStr - 1) =3D 0; =20 // // The field value MAY be preceded by any amount of LWS, though a single= SP is preferred. + // Note: LWS =3D [CRLF] 1*(SP|HT), it can be '\r\n ' or '\r\n\t' or ' '= or '\t'. + // CRLF =3D '\r\n'. + // SP =3D ' '. + // HT =3D '\t' (Tab). // while (TRUE) { if (*FieldValueStr =3D=3D ' ' || *FieldValueStr =3D=3D '\t') { + // + // Boundary condition check.=20 + // + if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 1) { + return NULL; =20 + } + =20 FieldValueStr ++; - } else if (*FieldValueStr =3D=3D '\r' && *(FieldValueStr + 1) =3D=3D '= \n' && - (*(FieldValueStr + 2) =3D=3D ' ' || *(FieldValueStr + 2) = =3D=3D '\t')) { - FieldValueStr =3D FieldValueStr + 3; + } else if (*FieldValueStr =3D=3D '\r') { + // + // Boundary condition check.=20 + // + if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 3) { + return NULL; =20 + } + + if (*(FieldValueStr + 1) =3D=3D '\n' && (*(FieldValueStr + 2) =3D=3D= ' ' || *(FieldValueStr + 2) =3D=3D '\t')) { + FieldValueStr =3D FieldValueStr + 3; + } } else { break; } } =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 23:24:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514252039888468.32121567884406; Mon, 25 Dec 2017 17:33:59 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6AF76222CB327; Mon, 25 Dec 2017 17:29:04 -0800 (PST) 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 7ABC322225C1A for ; Mon, 25 Dec 2017 17:29:02 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Dec 2017 17:33:56 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.165]) by orsmga002.jf.intel.com with ESMTP; 25 Dec 2017 17:33:55 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,457,1508828400"; d="scan'208";a="21327532" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 26 Dec 2017 09:33:46 +0800 Message-Id: <1514252029-12720-3-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> References: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 2/5] MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Li= brary/DxeHttpLib/DxeHttpLib.c index 4d353d7..27b94e3 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -369,10 +369,12 @@ HttpParseUrl ( UINT32 Field; UINT32 OldField; BOOLEAN FoundAt; EFI_STATUS Status; HTTP_URL_PARSER *Parser; + + Parser =3D NULL; =20 if (Url =3D=3D NULL || Length =3D=3D 0 || UrlParser =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 @@ -399,10 +401,11 @@ HttpParseUrl ( // State =3D NetHttpParseUrlChar (*Char, State); =20 switch (State) { case UrlParserStateMax: + FreePool (Parser); return EFI_INVALID_PARAMETER; =20 case UrlParserSchemeColon: case UrlParserSchemeColonSlash: case UrlParserSchemeColonSlashSlash: @@ -461,10 +464,11 @@ HttpParseUrl ( // If has authority component, continue to parse the username, host and = port. // if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) !=3D 0) { Status =3D NetHttpParseAuthority (Url, FoundAt, Parser); if (EFI_ERROR (Status)) { + FreePool (Parser); return Status; } } =20 *UrlParser =3D Parser; @@ -1525,10 +1529,11 @@ HttpSetFieldNameAndValue ( HttpHeader->FieldName[FieldNameSize - 1] =3D 0; =20 FieldValueSize =3D AsciiStrSize (FieldValue); HttpHeader->FieldValue =3D AllocateZeroPool (FieldValueSize); if (HttpHeader->FieldValue =3D=3D NULL) { + FreePool (HttpHeader->FieldName); return EFI_OUT_OF_RESOURCES; } CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize); HttpHeader->FieldValue[FieldValueSize - 1] =3D 0; =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 23:24:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514252042386238.35997214479664; Mon, 25 Dec 2017 17:34:02 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C3BFC222CB320; Mon, 25 Dec 2017 17:29:06 -0800 (PST) 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 EAB69222447D9 for ; Mon, 25 Dec 2017 17:29:03 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Dec 2017 17:33:57 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.165]) by orsmga002.jf.intel.com with ESMTP; 25 Dec 2017 17:33:56 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,457,1508828400"; d="scan'208";a="21327536" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 26 Dec 2017 09:33:47 +0800 Message-Id: <1514252029-12720-4-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> References: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 3/5] MdeModulePkg/DxeHttpLib: Check the input parameters for some APIs. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- MdeModulePkg/Include/Library/HttpLib.h | 1 + MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/= Library/HttpLib.h index 8539820..88b56ae 100644 --- a/MdeModulePkg/Include/Library/HttpLib.h +++ b/MdeModulePkg/Include/Library/HttpLib.h @@ -370,10 +370,11 @@ HttpFindHeader ( @param[in] FieldName FieldName of this HttpHeader, a NULL= terminated ASCII string. @param[in] FieldValue FieldValue of this HttpHeader, a NUL= L terminated ASCII string. =20 =20 @retval EFI_SUCCESS The FieldName and FieldValue are set int= o HttpHeader successfully. + @retval EFI_INVALID_PARAMETER The parameter is invalid. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources. =20 **/ EFI_STATUS EFIAPI diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Li= brary/DxeHttpLib/DxeHttpLib.c index 27b94e3..38ded5d 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -1396,10 +1396,14 @@ HttpIsMessageComplete ( IN VOID *MsgParser ) { HTTP_BODY_PARSER *Parser; =20 + if (MsgParser =3D=3D NULL) { + return FALSE; + } + Parser =3D (HTTP_BODY_PARSER*) MsgParser; =20 if (Parser->State =3D=3D BodyParserComplete) { return TRUE; } @@ -1497,10 +1501,11 @@ AsciiStrGetNextToken ( @param[in] FieldName FieldName of this HttpHeader, a NULL ter= minated ASCII string. @param[in] FieldValue FieldValue of this HttpHeader, a NULL te= rminated ASCII string. =20 =20 @retval EFI_SUCCESS The FieldName and FieldValue are set int= o HttpHeader successfully. + @retval EFI_INVALID_PARAMETER The parameter is invalid. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources. =20 **/ EFI_STATUS EFIAPI @@ -1511,10 +1516,14 @@ HttpSetFieldNameAndValue ( ) { UINTN FieldNameSize; UINTN FieldValueSize; =20 + if (HttpHeader =3D=3D NULL || FieldName =3D=3D NULL || FieldValue =3D=3D= NULL) { + return EFI_INVALID_PARAMETER; + } + if (HttpHeader->FieldName !=3D NULL) { FreePool (HttpHeader->FieldName); } if (HttpHeader->FieldValue !=3D NULL) { FreePool (HttpHeader->FieldValue); @@ -1728,14 +1737,10 @@ HttpGenRequestMessage ( VOID *HttpHdr; EFI_HTTP_HEADER **AppendList; UINTN Index; EFI_HTTP_UTILITIES_PROTOCOL *HttpUtilitiesProtocol; =20 - - ASSERT (Message !=3D NULL); - - *RequestMsg =3D NULL; Status =3D EFI_SUCCESS; HttpHdrSize =3D 0; MsgSize =3D 0; Success =3D FALSE; HttpHdr =3D NULL; @@ -1746,11 +1751,12 @@ HttpGenRequestMessage ( // 1. If we have a Request, we cannot have a NULL Url // 2. If we have a Request, HeaderCount can not be non-zero // 3. If we do not have a Request, HeaderCount should be zero // 4. If we do not have Request and Headers, we need at least a message-= body // - if ((Message->Data.Request !=3D NULL && Url =3D=3D NULL) || + if ((Message =3D=3D NULL || RequestMsg =3D=3D NULL || RequestMsgSize =3D= =3D NULL) ||=20 + (Message->Data.Request !=3D NULL && Url =3D=3D NULL) || (Message->Data.Request !=3D NULL && Message->HeaderCount =3D=3D 0) || (Message->Data.Request =3D=3D NULL && Message->HeaderCount !=3D 0) || (Message->Data.Request =3D=3D NULL && Message->HeaderCount =3D=3D 0 = && Message->BodyLength =3D=3D 0)) { return EFI_INVALID_PARAMETER; } @@ -1827,10 +1833,11 @@ HttpGenRequestMessage ( MsgSize +=3D Message->BodyLength; =20 // // memory for the string that needs to be sent to TCP // + *RequestMsg =3D NULL; *RequestMsg =3D AllocateZeroPool (MsgSize); if (*RequestMsg =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto Exit; } @@ -2052,11 +2059,19 @@ HttpIsValidHttpHeader ( IN CHAR8 *FieldName ) { UINTN Index; =20 + if (FieldName =3D=3D NULL) { + return FALSE; + } + for (Index =3D 0; Index < DeleteCount; Index++) { + if (DeleteList[Index] =3D=3D NULL) { + continue; + } + =20 if (AsciiStrCmp (FieldName, DeleteList[Index]) =3D=3D 0) { return FALSE; } } =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 23:24:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514252044958548.8425209481983; Mon, 25 Dec 2017 17:34:04 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2EEF5222F4E04; Mon, 25 Dec 2017 17:29:07 -0800 (PST) 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 68817208F7A3C for ; Mon, 25 Dec 2017 17:29:05 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Dec 2017 17:33:59 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.165]) by orsmga002.jf.intel.com with ESMTP; 25 Dec 2017 17:33:58 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,457,1508828400"; d="scan'208";a="21327540" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 26 Dec 2017 09:33:48 +0800 Message-Id: <1514252029-12720-5-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> References: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 4/5] MdeModulePkg/DxeHttpLib: Correct some return Status. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- MdeModulePkg/Include/Library/HttpLib.h | 5 +++-- MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/= Library/HttpLib.h index 88b56ae..285a831 100644 --- a/MdeModulePkg/Include/Library/HttpLib.h +++ b/MdeModulePkg/Include/Library/HttpLib.h @@ -284,12 +284,13 @@ HttpInitMsgParser ( @param[in] BodyLength Length in bytes of the Body. @param[in] Body Pointer to the buffer of the mes= sage-body to be parsed. =20 @retval EFI_SUCCESS Successfully parse the message-body. @retval EFI_INVALID_PARAMETER MsgParser is NULL or Body is NULL or = BodyLength is 0. - @retval Others Operation aborted. - + @retval EFI_ABORTED Operation aborted. + @retval Other Error happened while parsing message = body. + =20 **/ EFI_STATUS EFIAPI HttpParseMessageBody ( IN OUT VOID *MsgParser, diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Li= brary/DxeHttpLib/DxeHttpLib.c index 38ded5d..327ca9e 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -152,11 +152,11 @@ NetHttpParseAuthorityChar ( @param[in] Url The pointer to a HTTP URL string. @param[in] FoundAt TRUE if there is an at sign ('@') in the= authority component. @param[in, out] UrlParser Pointer to the buffer of the parse resul= t. =20 @retval EFI_SUCCESS Successfully parse the authority. - @retval Other Error happened. + @retval EFI_INVALID_PARAMETER The Url is invalid to parse the authorit= y component. =20 **/ EFI_STATUS NetHttpParseAuthority ( IN CHAR8 *Url, @@ -569,11 +569,11 @@ HttpUrlGetIp4 ( } =20 Parser =3D (HTTP_URL_PARSER*) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) =3D=3D 0) { - return EFI_INVALID_PARAMETER; + return EFI_NOT_FOUND; } =20 Ip4String =3D AllocatePool (Parser->FieldData[HTTP_URI_FIELD_HOST].Lengt= h + 1); if (Ip4String =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -632,11 +632,11 @@ HttpUrlGetIp6 ( } =20 Parser =3D (HTTP_URL_PARSER*) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) =3D=3D 0) { - return EFI_INVALID_PARAMETER; + return EFI_NOT_FOUND; } =20 // // IP-literal =3D "[" ( IPv6address / IPvFuture ) "]" // @@ -711,11 +711,11 @@ HttpUrlGetPort ( Index =3D 0; =20 Parser =3D (HTTP_URL_PARSER*) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) =3D=3D 0) { - return EFI_INVALID_PARAMETER; + return EFI_NOT_FOUND; } =20 PortString =3D AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PORT].Leng= th + 1); if (PortString =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -1130,11 +1130,12 @@ HttpInitMsgParser ( @param[in] BodyLength Length in bytes of the Body. @param[in] Body Pointer to the buffer of the mes= sage-body to be parsed. =20 @retval EFI_SUCCESS Successfully parse the message-body. @retval EFI_INVALID_PARAMETER MsgParser is NULL or Body is NULL or = BodyLength is 0. - @retval Others Operation aborted. + @retval EFI_ABORTED Operation aborted. + @retval Other Error happened while parsing message = body. =20 **/ EFI_STATUS EFIAPI HttpParseMessageBody ( --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 23:24:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514252047625352.87808278742807; Mon, 25 Dec 2017 17:34:07 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7FA47222CB332; Mon, 25 Dec 2017 17:29:09 -0800 (PST) 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 E4551222F4E00 for ; Mon, 25 Dec 2017 17:29:06 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Dec 2017 17:34:00 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.165]) by orsmga002.jf.intel.com with ESMTP; 25 Dec 2017 17:33:59 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,457,1508828400"; d="scan'208";a="21327545" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 26 Dec 2017 09:33:49 +0800 Message-Id: <1514252029-12720-6-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> References: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 5/5] MdeModulePkg/DxeHttpLib: Refine some coding style. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wang Fan , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- MdeModulePkg/Include/Library/HttpLib.h | 4 +- MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 118 +++++++++++++----------= ---- 2 files changed, 60 insertions(+), 62 deletions(-) diff --git a/MdeModulePkg/Include/Library/HttpLib.h b/MdeModulePkg/Include/= Library/HttpLib.h index 285a831..9975aea 100644 --- a/MdeModulePkg/Include/Library/HttpLib.h +++ b/MdeModulePkg/Include/Library/HttpLib.h @@ -432,13 +432,13 @@ HttpFreeHeaderFields ( @param[in] Url The URL of a remote host. @param[out] RequestMsg Pointer to the created HTTP request mess= age. NULL if any error occured. @param[out] RequestMsgSize Size of the RequestMsg (in bytes). =20 - @return EFI_SUCCESS If HTTP request string was created succe= ssfully + @retval EFI_SUCCESS If HTTP request string was created succe= ssfully. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources. - @retval EFI_INVALID_PARAMETER The input arguments are invalid + @retval EFI_INVALID_PARAMETER The input arguments are invalid. =20 **/ EFI_STATUS EFIAPI HttpGenRequestMessage ( diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Li= brary/DxeHttpLib/DxeHttpLib.c index 327ca9e..4e5cf84 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -53,11 +53,12 @@ UriPercentDecode ( Index =3D 0; Offset =3D 0; HexStr[2] =3D '\0'; while (Index < BufferLength) { if (Buffer[Index] =3D=3D '%') { - if (Index + 1 >=3D BufferLength || Index + 2 >=3D BufferLength || !N= ET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2])) { + if (Index + 1 >=3D BufferLength || Index + 2 >=3D BufferLength ||=20 + !NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[I= ndex+2])) { return EFI_INVALID_PARAMETER; } HexStr[0] =3D Buffer[Index+1]; HexStr[1] =3D Buffer[Index+2]; ResultBuffer[Offset] =3D (CHAR8) AsciiStrHexToUintn (HexStr); @@ -506,11 +507,11 @@ HttpUrlGetHostName ( =20 if (Url =3D=3D NULL || UrlParser =3D=3D NULL || HostName =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - Parser =3D (HTTP_URL_PARSER*) UrlParser; + Parser =3D (HTTP_URL_PARSER *) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) =3D=3D 0) { return EFI_NOT_FOUND; } =20 @@ -566,11 +567,11 @@ HttpUrlGetIp4 ( =20 if (Url =3D=3D NULL || UrlParser =3D=3D NULL || Ip4Address =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - Parser =3D (HTTP_URL_PARSER*) UrlParser; + Parser =3D (HTTP_URL_PARSER *) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) =3D=3D 0) { return EFI_NOT_FOUND; } =20 @@ -629,11 +630,11 @@ HttpUrlGetIp6 ( =20 if (Url =3D=3D NULL || UrlParser =3D=3D NULL || Ip6Address =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - Parser =3D (HTTP_URL_PARSER*) UrlParser; + Parser =3D (HTTP_URL_PARSER *) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) =3D=3D 0) { return EFI_NOT_FOUND; } =20 @@ -694,25 +695,25 @@ HttpUrlGetPort ( IN CHAR8 *Url, IN VOID *UrlParser, OUT UINT16 *Port ) { - CHAR8 *PortString; - EFI_STATUS Status; - UINTN Index; - UINTN Data; - UINT32 ResultLength; + 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; =20 - Parser =3D (HTTP_URL_PARSER*) UrlParser; + Parser =3D (HTTP_URL_PARSER *) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) =3D=3D 0) { return EFI_NOT_FOUND; } =20 @@ -786,11 +787,11 @@ HttpUrlGetPath ( =20 if (Url =3D=3D NULL || UrlParser =3D=3D NULL || Path =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - Parser =3D (HTTP_URL_PARSER*) UrlParser; + Parser =3D (HTTP_URL_PARSER *) UrlParser; =20 if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) =3D=3D 0) { return EFI_NOT_FOUND; } =20 @@ -1156,21 +1157,21 @@ HttpParseMessageBody ( =20 if (MsgParser =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - Parser =3D (HTTP_BODY_PARSER*) MsgParser; + Parser =3D (HTTP_BODY_PARSER *) MsgParser; =20 if (Parser->IgnoreBody) { Parser->State =3D BodyParserComplete; if (Parser->Callback !=3D NULL) { Status =3D Parser->Callback ( - BodyParseEventOnComplete, - Body, - 0, - Parser->Context - ); + BodyParseEventOnComplete, + Body, + 0, + Parser->Context + ); if (EFI_ERROR (Status)) { return Status; } } return EFI_SUCCESS; @@ -1198,30 +1199,30 @@ HttpParseMessageBody ( // // Identity transfer-coding, just notify user to save the body data. // if (Parser->Callback !=3D NULL) { Status =3D Parser->Callback ( - BodyParseEventOnData, - Char, - MIN (BodyLength, Parser->ContentLength - Parser->Parsed= BodyLength), - Parser->Context - ); + BodyParseEventOnData, + Char, + MIN (BodyLength, Parser->ContentLength - Parser= ->ParsedBodyLength), + Parser->Context + ); if (EFI_ERROR (Status)) { return Status; } } Char +=3D MIN (BodyLength, Parser->ContentLength - Parser->ParsedBod= yLength); Parser->ParsedBodyLength +=3D MIN (BodyLength, Parser->ContentLength= - Parser->ParsedBodyLength); if (Parser->ParsedBodyLength =3D=3D Parser->ContentLength) { Parser->State =3D BodyParserComplete; if (Parser->Callback !=3D NULL) { Status =3D Parser->Callback ( - BodyParseEventOnComplete, - Char, - 0, - Parser->Context - ); + BodyParseEventOnComplete, + Char, + 0, + Parser->Context + ); if (EFI_ERROR (Status)) { return Status; } } } @@ -1302,15 +1303,15 @@ HttpParseMessageBody ( if (*Char =3D=3D '\n') { Parser->State =3D BodyParserComplete; Char++; if (Parser->Callback !=3D NULL) { Status =3D Parser->Callback ( - BodyParseEventOnComplete, - Char, - 0, - Parser->Context - ); + BodyParseEventOnComplete, + Char, + 0, + Parser->Context + ); if (EFI_ERROR (Status)) { return Status; } } break; @@ -1332,15 +1333,15 @@ HttpParseMessageBody ( // RemainderLengthInThis =3D BodyLength - (Char - Body); LengthForCallback =3D MIN (Parser->CurrentChunkSize - Parser->Curren= tChunkParsedSize, RemainderLengthInThis); if (Parser->Callback !=3D NULL) { Status =3D Parser->Callback ( - BodyParseEventOnData, - Char, - LengthForCallback, - Parser->Context - ); + BodyParseEventOnData, + Char, + LengthForCallback, + Parser->Context + ); if (EFI_ERROR (Status)) { return Status; } } Char +=3D LengthForCallback; @@ -1401,11 +1402,11 @@ HttpIsMessageComplete ( =20 if (MsgParser =3D=3D NULL) { return FALSE; } =20 - Parser =3D (HTTP_BODY_PARSER*) MsgParser; + Parser =3D (HTTP_BODY_PARSER *) MsgParser; =20 if (Parser->State =3D=3D BodyParserComplete) { return TRUE; } return FALSE; @@ -1435,11 +1436,11 @@ HttpGetEntityLength ( =20 if (MsgParser =3D=3D NULL || ContentLength =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - Parser =3D (HTTP_BODY_PARSER*) MsgParser; + Parser =3D (HTTP_BODY_PARSER *) MsgParser; =20 if (!Parser->ContentLengthIsValid) { return EFI_NOT_READY; } =20 @@ -1473,11 +1474,10 @@ HttpFreeMsgParser ( @return Pointer to the next string. @return NULL if not find or String is NULL. =20 **/ CHAR8 * -EFIAPI AsciiStrGetNextToken ( IN CONST CHAR8 *String, IN CHAR8 Separator ) { @@ -1618,20 +1618,20 @@ HttpGetFieldNameAndValue ( while (TRUE) { if (*FieldValueStr =3D=3D ' ' || *FieldValueStr =3D=3D '\t') { // // Boundary condition check.=20 // - if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 1) { + if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 1) { return NULL; =20 } =20 FieldValueStr ++; } else if (*FieldValueStr =3D=3D '\r') { // // Boundary condition check.=20 // - if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 3) { + if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 3) { return NULL; =20 } =20 if (*(FieldValueStr + 1) =3D=3D '\n' && (*(FieldValueStr + 2) =3D=3D= ' ' || *(FieldValueStr + 2) =3D=3D '\t')) { FieldValueStr =3D FieldValueStr + 3; @@ -1713,13 +1713,13 @@ HttpFreeHeaderFields ( @param[in] Url The URL of a remote host. @param[out] RequestMsg Pointer to the created HTTP request mess= age. NULL if any error occured. @param[out] RequestMsgSize Size of the RequestMsg (in bytes). =20 - @return EFI_SUCCESS If HTTP request string was created succe= ssfully + @retval EFI_SUCCESS If HTTP request string was created succe= ssfully. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources. - @retval EFI_INVALID_PARAMETER The input arguments are invalid + @retval EFI_INVALID_PARAMETER The input arguments are invalid. =20 **/ EFI_STATUS EFIAPI HttpGenRequestMessage ( @@ -1767,11 +1767,11 @@ HttpGenRequestMessage ( // Locate the HTTP_UTILITIES protocol. // Status =3D gBS->LocateProtocol ( &gEfiHttpUtilitiesProtocolGuid, NULL, - (VOID **)&HttpUtilitiesProtocol + (VOID **) &HttpUtilitiesProtocol ); =20 if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR,"Failed to locate Http Utilities protocol. Statu= s =3D %r.\n", Status)); return Status; @@ -1791,24 +1791,22 @@ HttpGenRequestMessage ( =20 // // Build raw HTTP Headers // Status =3D HttpUtilitiesProtocol->Build ( - HttpUtilitiesProtocol, - 0, - NULL, - 0, - NULL, - Message->HeaderCount, - AppendList, - &HttpHdrSize, - &HttpHdr - ); - - if (AppendList !=3D NULL) { - FreePool (AppendList); - } + HttpUtilitiesProtocol, + 0, + NULL, + 0, + NULL, + Message->HeaderCount, + AppendList, + &HttpHdrSize, + &HttpHdr + ); + + FreePool (AppendList); =20 if (EFI_ERROR (Status) || HttpHdr =3D=3D NULL){ return Status; } } @@ -1834,11 +1832,11 @@ HttpGenRequestMessage ( MsgSize +=3D Message->BodyLength; =20 // // memory for the string that needs to be sent to TCP // - *RequestMsg =3D NULL; + *RequestMsg =3D NULL; *RequestMsg =3D AllocateZeroPool (MsgSize); if (*RequestMsg =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto Exit; } --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel