From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=siyuan.fu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 780172112946C for ; Wed, 12 Sep 2018 01:57:13 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 01:57:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,364,1531810800"; d="scan'208";a="88055650" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga004.fm.intel.com with ESMTP; 12 Sep 2018 01:54:52 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 12 Sep 2018 01:54:51 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 12 Sep 2018 01:54:51 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.240]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.16]) with mapi id 14.03.0319.002; Wed, 12 Sep 2018 16:54:48 +0800 From: "Fu, Siyuan" To: "Wu, Jiaxin" , "edk2-devel@lists.01.org" CC: Stephen Benjamin , Laszlo Ersek , "Ye, Ting" Thread-Topic: [Patch] MdeModulePkg/Library/DxeHttpLib: Handle the blank value in HTTP header. Thread-Index: AQHURB9axzs4xQMHckikJaUlmP1TjaTsZDqQ Date: Wed, 12 Sep 2018 08:54:48 +0000 Message-ID: References: <20180904071722.7728-1-Jiaxin.wu@intel.com> In-Reply-To: <20180904071722.7728-1-Jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNGQ3MWJhOTctYzNjMC00Zjg5LTg1MzYtMjY4OTJlYTdkYjc3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiVTBkSlZKdTZEdkR5RnJSRk9sMFlHMFVoXC92K3dtVkpBbldjRldyWlJUbURNajVoY3BuVlozeHZmckFSeWlkZFAifQ== dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] MdeModulePkg/Library/DxeHttpLib: Handle the blank value in HTTP header. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Sep 2018 08:57:13 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Fu Siyuan > -----Original Message----- > From: Wu, Jiaxin > Sent: Tuesday, September 4, 2018 3:17 PM > To: edk2-devel@lists.01.org > Cc: Stephen Benjamin ; Laszlo Ersek > ; Ye, Ting ; Fu, Siyuan > ; Wu, Jiaxin > Subject: [Patch] MdeModulePkg/Library/DxeHttpLib: Handle the blank value > in HTTP header. >=20 > This patch is to resolve the lock-up issue if the value of HTTP header > is blank. The issue is recorded @ > https://bugzilla.tianocore.org/show_bug.cgi?id=3D1102. >=20 > Cc: Stephen Benjamin > Cc: Laszlo Ersek > Cc: Ye Ting > Cc: Fu Siyuan > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Wu Jiaxin > --- > MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 57 +++++++++++++++----- > 1 file changed, 44 insertions(+), 13 deletions(-) >=20 > diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c > b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c > index 5fbb50d03a..2fc3da8a2d 100644 > --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c > +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c > @@ -1595,63 +1595,94 @@ HttpGetFieldNameAndValue ( > return NULL; > } >=20 > // > // Each header field consists of a name followed by a colon (":") and > the field value. > + // The field value MAY be preceded by any amount of LWS, though a > single SP is preferred. > + // > + // message-header =3D field-name ":" [ field-value ] > + // field-name =3D token > + // field-value =3D *( field-content | LWS ) > + // > + // Note: "*(element)" allows any number element, including zero; > "1*(element)" requires at least one element. > + // [element] means element is optional. > + // LWS =3D [CRLF] 1*(SP|HT), it can be ' ' or '\t' or '\r\n ' o= r > '\r\n\t'. > + // CRLF =3D '\r\n'. > + // SP =3D ' '. > + // HT =3D '\t' (Tab). > // > FieldNameStr =3D String; > FieldValueStr =3D AsciiStrGetNextToken (FieldNameStr, ':'); > if (FieldValueStr =3D=3D NULL) { > return NULL; > } >=20 > // > - // Replace ':' with 0 > + // Replace ':' with 0, then FieldName has been retrived from String. > // > *(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). > + // Handle FieldValueStr, skip all the preceded LWS. > // > while (TRUE) { > if (*FieldValueStr =3D=3D ' ' || *FieldValueStr =3D=3D '\t') { > // > // Boundary condition check. > // > if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 1) { > + // > + // Wrong String format! > + // > return NULL; > } >=20 > FieldValueStr ++; > } else if (*FieldValueStr =3D=3D '\r') { > // > // Boundary condition check. > // > if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 3) { > - return NULL; > + // > + // No more preceded LWS, so break here. > + // > + break; > } >=20 > - if (*(FieldValueStr + 1) =3D=3D '\n' && (*(FieldValueStr + 2) =3D= =3D ' ' || > *(FieldValueStr + 2) =3D=3D '\t')) { > - FieldValueStr =3D FieldValueStr + 3; > + if (*(FieldValueStr + 1) =3D=3D '\n' ) { > + if (*(FieldValueStr + 2) =3D=3D ' ' || *(FieldValueStr + 2) =3D= =3D '\t') > { > + FieldValueStr =3D FieldValueStr + 3; > + } else { > + // > + // No more preceded LWS, so break here. > + // > + break; > + } > + } else { > + // > + // Wrong String format! > + // > + return NULL; > } > } else { > + // > + // No more preceded LWS, so break here. > + // > break; > } > } >=20 > - // > - // Header fields can be extended over multiple lines by preceding each > extra > - // line with at least one SP or HT. > - // > StrPtr =3D FieldValueStr; > do { > + // > + // Handle the LWS within the field value. > + // > StrPtr =3D AsciiStrGetNextToken (StrPtr, '\r'); > if (StrPtr =3D=3D NULL || *StrPtr !=3D '\n') { > + // > + // Wrong String format! > + // > return NULL; > } >=20 > StrPtr++; > } while (*StrPtr =3D=3D ' ' || *StrPtr =3D=3D '\t'); > -- > 2.17.1.windows.2