From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Wu, Hao A" <hao.a.wu@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Kinney, Michael D" <michael.d.kinney@intel.com>,
"Tian, Feng" <feng.tian@intel.com>,
"Zeng, Star" <star.zeng@intel.com>
Subject: Re: [PATCH] MdeModulePkg/PrintLib: Add missing return status check for Print APIs
Date: Tue, 3 Jan 2017 07:20:05 +0000 [thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503A8DA668@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <1482727720-8060-1-git-send-email-hao.a.wu@intel.com>
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 <hao.a.wu@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>;
> Kinney, Michael D <michael.d.kinney@intel.com>; Tian, Feng
> <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [PATCH] MdeModulePkg/PrintLib: Add missing return status check for
> Print APIs
>
> For the following APIs in PrintLib instance
> MdeModulePkg\Library\DxePrintLibPrint2Protocol:
> UnicodeVSPrint
> UnicodeSPrint
> UnicodeVSPrintAsciiFormat
> UnicodeSPrintAsciiFormat
> AsciiVSPrint
> AsciiSPrint
> AsciiVSPrintUnicodeFormat
> AsciiSPrintUnicodeFormat
>
> 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.
>
> 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.
>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Michael Kinney <michael.d.kinney@intel.com>
> Cc: Feng Tian <feng.tian@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
> .../Library/DxePrintLibPrint2Protocol/PrintLib.c | 94 +++++++++++++---------
> 1 file changed, 56 insertions(+), 38 deletions(-)
>
> 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, this
> library instance is only for this code base.
>
> -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
> 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
> @@ -71,7 +71,8 @@ PrintLibConstructor (
> @param BaseListMarker BASE_LIST style variable argument list consumed
> by processing Format.
> @param Size The size, in bytes, of the BaseListMarker buffer.
>
> - @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.
>
> **/
> 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;
> }
>
> @@ -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 = DxePrintLibPrint2ProtocolVaListToBaseList (
> + FALSE,
> + (CHAR8 *)FormatString,
> + Marker,
> + (BASE_LIST)BaseListMarker,
> + sizeof (BaseListMarker) - 8
> + );
> + if (!Converted) {
> + return 0;
> + }
>
> 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 = DxePrintLibPrint2ProtocolVaListToBaseList (
> + TRUE,
> + FormatString,
> + Marker,
> + (BASE_LIST)BaseListMarker,
> + sizeof (BaseListMarker) - 8
> + );
> + if (!Converted) {
> + return 0;
> + }
>
> return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString,
> (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 = DxePrintLibPrint2ProtocolVaListToBaseList (
> + TRUE,
> + FormatString,
> + Marker,
> + (BASE_LIST)BaseListMarker,
> + sizeof (BaseListMarker) - 8
> + );
> + if (!Converted) {
> + return 0;
> + }
>
> 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 = DxePrintLibPrint2ProtocolVaListToBaseList (
> + FALSE,
> + (CHAR8 *)FormatString,
> + Marker,
> + (BASE_LIST)BaseListMarker,
> + sizeof (BaseListMarker) - 8
> + );
> + if (!Converted) {
> + return 0;
> + }
>
> return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString,
> (BASE_LIST)BaseListMarker);
> }
> --
> 1.9.5.msysgit.0
prev parent reply other threads:[~2017-01-03 7:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-26 4:48 [PATCH] MdeModulePkg/PrintLib: Add missing return status check for Print APIs Hao Wu
2017-01-03 7:20 ` Yao, Jiewen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74D8A39837DF1E4DA445A8C0B3885C503A8DA668@shsmsx102.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox