From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 EBCAC817DA for ; Mon, 2 Jan 2017 23:20:09 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 02 Jan 2017 23:20:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,451,1477983600"; d="scan'208";a="209034384" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga004.fm.intel.com with ESMTP; 02 Jan 2017 23:20:09 -0800 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 2 Jan 2017 23:20:09 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 2 Jan 2017 23:20:08 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.177]) with mapi id 14.03.0248.002; Tue, 3 Jan 2017 15:20:07 +0800 From: "Yao, Jiewen" To: "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Tian, Feng" , "Zeng, Star" Thread-Topic: [PATCH] MdeModulePkg/PrintLib: Add missing return status check for Print APIs Thread-Index: AQHSXzNaFR0skx7gq0KvMeLLGz/ykqEmZS0Q Date: Tue, 3 Jan 2017 07:20:05 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503A8DA668@shsmsx102.ccr.corp.intel.com> References: <1482727720-8060-1-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1482727720-8060-1-git-send-email-hao.a.wu@intel.com> Accept-Language: zh-CN, 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/PrintLib: Add missing return status check for Print APIs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jan 2017 07:20:10 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen.yao@intel.com > -----Original Message----- > From: Wu, Hao A > Sent: Monday, December 26, 2016 12:49 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Yao, Jiewen ; > Kinney, Michael D ; Tian, Feng > ; Zeng, Star > Subject: [PATCH] MdeModulePkg/PrintLib: Add missing return status check f= or > Print APIs >=20 > For the following APIs in PrintLib instance > MdeModulePkg\Library\DxePrintLibPrint2Protocol: > UnicodeVSPrint > UnicodeSPrint > UnicodeVSPrintAsciiFormat > UnicodeSPrintAsciiFormat > AsciiVSPrint > AsciiSPrint > AsciiVSPrintUnicodeFormat > AsciiSPrintUnicodeFormat >=20 > The internal function DxePrintLibPrint2ProtocolVaListToBaseList() will be > called to convert a VA_LIST to a BASE_LIST. However, those APIs miss > checking the return value of the internal function. >=20 > This commit adds codes to check the return value. If the VA_LIST fails to > be converted to a BASE_LIST, those PrintLib APIs will return 0 and leave > the output 'StartOfBuffer' unmodified. >=20 > Cc: Jiewen Yao > Cc: Michael Kinney > Cc: Feng Tian > Cc: Star Zeng > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu > --- > .../Library/DxePrintLibPrint2Protocol/PrintLib.c | 94 +++++++++++++---= ------ > 1 file changed, 56 insertions(+), 38 deletions(-) >=20 > diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c > b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c > index 4acdcb8..ecafc49 100644 > --- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c > +++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c > @@ -6,7 +6,7 @@ > protocol related to this implementation, not in the public spec. So, t= his > library instance is only for this code base. >=20 > -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
> +Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
> 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 > @@ -71,7 +71,8 @@ PrintLibConstructor ( > @param BaseListMarker BASE_LIST style variable argument list consume= d > by processing Format. > @param Size The size, in bytes, of the BaseListMarker buff= er. >=20 > - @return The number of bytes in BaseListMarker. 0 if BaseListMarker is= too > small. > + @return TRUE The VA_LIST has been converted to BASE_LIST. > + @return FALSE The VA_LIST has not been converted to BASE_LIST. >=20 > **/ > BOOLEAN > @@ -205,6 +206,7 @@ DxePrintLibPrint2ProtocolVaListToBaseList ( > // If BASE_LIST is larger than Size, then return FALSE > // > if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size= ) { > + DEBUG ((DEBUG_ERROR, "The input variable argument list is too long= . > Please consider breaking into multiple print calls.\n")); > return FALSE; > } >=20 > @@ -264,15 +266,19 @@ UnicodeVSPrint ( > IN VA_LIST Marker > ) > { > - UINT64 BaseListMarker[256 / sizeof (UINT64)]; > - > - DxePrintLibPrint2ProtocolVaListToBaseList ( > - FALSE, > - (CHAR8 *)FormatString, > - Marker, > - (BASE_LIST)BaseListMarker, > - sizeof (BaseListMarker) - 8 > - ); > + UINT64 BaseListMarker[256 / sizeof (UINT64)]; > + BOOLEAN Converted; > + > + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( > + FALSE, > + (CHAR8 *)FormatString, > + Marker, > + (BASE_LIST)BaseListMarker, > + sizeof (BaseListMarker) - 8 > + ); > + if (!Converted) { > + return 0; > + } >=20 > return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, > (BASE_LIST)BaseListMarker); > } > @@ -417,15 +423,19 @@ UnicodeVSPrintAsciiFormat ( > IN VA_LIST Marker > ) > { > - UINT64 BaseListMarker[256 / sizeof (UINT64)]; > - > - DxePrintLibPrint2ProtocolVaListToBaseList ( > - TRUE, > - FormatString, > - Marker, > - (BASE_LIST)BaseListMarker, > - sizeof (BaseListMarker) - 8 > - ); > + UINT64 BaseListMarker[256 / sizeof (UINT64)]; > + BOOLEAN Converted; > + > + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( > + TRUE, > + FormatString, > + Marker, > + (BASE_LIST)BaseListMarker, > + sizeof (BaseListMarker) - 8 > + ); > + if (!Converted) { > + return 0; > + } >=20 > return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatStr= ing, > (BASE_LIST)BaseListMarker); > } > @@ -621,15 +631,19 @@ AsciiVSPrint ( > IN VA_LIST Marker > ) > { > - UINT64 BaseListMarker[256 / sizeof (UINT64)]; > - > - DxePrintLibPrint2ProtocolVaListToBaseList ( > - TRUE, > - FormatString, > - Marker, > - (BASE_LIST)BaseListMarker, > - sizeof (BaseListMarker) - 8 > - ); > + UINT64 BaseListMarker[256 / sizeof (UINT64)]; > + BOOLEAN Converted; > + > + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( > + TRUE, > + FormatString, > + Marker, > + (BASE_LIST)BaseListMarker, > + sizeof (BaseListMarker) - 8 > + ); > + if (!Converted) { > + return 0; > + } >=20 > return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, > (BASE_LIST)BaseListMarker); > } > @@ -771,15 +785,19 @@ AsciiVSPrintUnicodeFormat ( > IN VA_LIST Marker > ) > { > - UINT64 BaseListMarker[256 / sizeof (UINT64)]; > - > - DxePrintLibPrint2ProtocolVaListToBaseList ( > - FALSE, > - (CHAR8 *)FormatString, > - Marker, > - (BASE_LIST)BaseListMarker, > - sizeof (BaseListMarker) - 8 > - ); > + UINT64 BaseListMarker[256 / sizeof (UINT64)]; > + BOOLEAN Converted; > + > + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( > + FALSE, > + (CHAR8 *)FormatString, > + Marker, > + (BASE_LIST)BaseListMarker, > + sizeof (BaseListMarker) - 8 > + ); > + if (!Converted) { > + return 0; > + } >=20 > return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatStr= ing, > (BASE_LIST)BaseListMarker); > } > -- > 1.9.5.msysgit.0