From: "Gao, Zhichao" <zhichao.gao@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
"xypron.glpk@gmx.de" <xypron.glpk@gmx.de>,
"Carsey, Jaben" <jaben.carsey@intel.com>,
"Ni, Ray" <ray.ni@intel.com>,
Leif Lindholm <leif.lindholm@linaro.org>,
"Gao, Zhichao" <zhichao.gao@intel.com>
Cc: "Gao, Liming" <liming.gao@intel.com>
Subject: Re: [edk2-devel] [PATCH 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
Date: Tue, 9 Apr 2019 05:33:05 +0000 [thread overview]
Message-ID: <3CE959C139B4C44DBEA1810E3AA6F9000B7C0E98@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <20190405012903.20796-1-xypron.glpk@gmx.de>
The patch code looks good to me.
But while I apply this patch, it will shows "error: corrupt patch at line 24" and " error: could not build fake ancestor". Maybe you direct change the patch file and remove some blank lines.
For Uefi BdsDxe driver, the variable "PlatfomLang" would be initialize all the time. But maybe other manufacturers may have their own Bds solution and do not set this variable. This patch makes the Shell app more compatible.
Without the patch warning.
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Heinrich Schuchardt
> Sent: Friday, April 5, 2019 9:29 AM
> To: Carsey, Jaben <jaben.carsey@intel.com>; Ni, Ray <ray.ni@intel.com>;
> Leif Lindholm <leif.lindholm@linaro.org>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Cc: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io; Heinrich Schuchardt
> <xypron.glpk@gmx.de>
> Subject: [edk2-devel] [PATCH 1/1] ShellPkg/CommandLib: avoid NULL
> derefence and memory leak
>
> Since TianoCore EDK2 commit d65f2cea36d1 ("ShellPkg/CommandLib: Locate
> proper UnicodeCollation instance") in edk2 the UEFI Shell crashes if EFI
> variable PlatformLang is not defined due to dereferencing gUnicodeCollation
> gUnicodeCollation (= NULL) in ShellCommandRegisterCommandName().
>
> Furthermore CommandInit() is leaking PlatformLang if gUnicodeCollation !=
> NULL.
>
> Close the memory leak and use the first UnicodeCollation instance if
> PlatfomLang is not defined.
>
> Fixes: d65f2cea36d1 ("ShellPkg/CommandLib: Locate proper
> UnicodeCollation
> instance")
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> .../UefiShellCommandLib/UefiShellCommandLib.c | 20 +++++++++++++-----
> -
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> index ddc4bb1567..e60279e5ac 100644
> --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> @@ -80,12 +80,10 @@ CommandInit(
> EFI_STATUS Status;
> CHAR8 *PlatformLang;
>
> - GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME,
> (VOID**)&PlatformLang, NULL);
> - if (PlatformLang == NULL) {
> - return EFI_UNSUPPORTED;
> - }
> -
> if (gUnicodeCollation == NULL) {
> +
> + GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME,
> + (VOID**)&PlatformLang, NULL);
> +
> Status = gBS->LocateHandleBuffer (
> ByProtocol,
> &gEfiUnicodeCollation2ProtocolGuid,
> @@ -113,6 +111,14 @@ CommandInit(
> continue;
> }
>
> + //
> + // Without clue provided use the first Unicode Collation2 protocol.
> + //
> + if (PlatformLang == NULL) {
> + gUnicodeCollation = Uc;
> + break;
> + }
> +
> //
> // Find the best matching matching language from the supported
> languages
> // of Unicode Collation2 protocol.
> @@ -132,7 +138,9 @@ CommandInit(
> if (Handles != NULL) {
> FreePool (Handles);
> }
> - FreePool (PlatformLang);
> + if (PlatformLang != NULL) {
> + FreePool (PlatformLang);
> + }
> }
>
> return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
> --
> 2.20.1
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
>
> View/Reply Online (#38597): https://edk2.groups.io/g/devel/message/38597
> Mute This Topic: https://groups.io/mt/30920004/1768756
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [zhichao.gao@intel.com] -=-=-=-=-=-=
next prev parent reply other threads:[~2019-04-09 5:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 1:29 [PATCH 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak Heinrich Schuchardt
2019-04-09 5:33 ` Gao, Zhichao [this message]
2019-04-09 6:03 ` [edk2-devel] " Heinrich Schuchardt
2019-04-09 16:37 ` Heinrich Schuchardt
2019-04-10 0:44 ` Gao, Zhichao
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=3CE959C139B4C44DBEA1810E3AA6F9000B7C0E98@SHSMSX101.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