From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: zhichao.gao@intel.com) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by groups.io with SMTP; Mon, 08 Apr 2019 22:33:10 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Apr 2019 22:33:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,328,1549958400"; d="scan'208";a="149234446" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 08 Apr 2019 22:33:09 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 8 Apr 2019 22:33:08 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 8 Apr 2019 22:33:08 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.164]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.42]) with mapi id 14.03.0415.000; Tue, 9 Apr 2019 13:33:06 +0800 From: "Gao, Zhichao" To: "devel@edk2.groups.io" , "xypron.glpk@gmx.de" , "Carsey, Jaben" , "Ni, Ray" , Leif Lindholm , "Gao, Zhichao" CC: "Gao, Liming" Subject: Re: [edk2-devel] [PATCH 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak Thread-Topic: [edk2-devel] [PATCH 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak Thread-Index: AQHU61Re5f6igwTAkkCxAnxV9DHQZKYzQrug Date: Tue, 9 Apr 2019 05:33:05 +0000 Message-ID: <3CE959C139B4C44DBEA1810E3AA6F9000B7C0E98@SHSMSX101.ccr.corp.intel.com> References: <20190405012903.20796-1-xypron.glpk@gmx.de> In-Reply-To: <20190405012903.20796-1-xypron.glpk@gmx.de> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: zhichao.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The patch code looks good to me. But while I apply this patch, it will shows "error: corrupt patch at line 2= 4" 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 > -----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 ; Ni, Ray ; > Leif Lindholm ; Ard Biesheuvel > > Cc: Ni, Ray ; devel@edk2.groups.io; Heinrich Schuchardt > > Subject: [edk2-devel] [PATCH 1/1] ShellPkg/CommandLib: avoid NULL > derefence and memory leak >=20 > 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 gUnicodeCollati= on > gUnicodeCollation (=3D NULL) in ShellCommandRegisterCommandName(). >=20 > Furthermore CommandInit() is leaking PlatformLang if gUnicodeCollation != =3D > NULL. >=20 > Close the memory leak and use the first UnicodeCollation instance if > PlatfomLang is not defined. >=20 > Fixes: d65f2cea36d1 ("ShellPkg/CommandLib: Locate proper > UnicodeCollation > instance") > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Heinrich Schuchardt > --- > .../UefiShellCommandLib/UefiShellCommandLib.c | 20 +++++++++++++----- > - > 1 file changed, 14 insertions(+), 6 deletions(-) >=20 > 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; >=20 > - GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, > (VOID**)&PlatformLang, NULL); > - if (PlatformLang =3D=3D NULL) { > - return EFI_UNSUPPORTED; > - } > - > if (gUnicodeCollation =3D=3D NULL) { > + > + GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, > + (VOID**)&PlatformLang, NULL); > + > Status =3D gBS->LocateHandleBuffer ( > ByProtocol, > &gEfiUnicodeCollation2ProtocolGuid, > @@ -113,6 +111,14 @@ CommandInit( > continue; > } >=20 > + // > + // Without clue provided use the first Unicode Collation2 protocol= . > + // > + if (PlatformLang =3D=3D NULL) { > + gUnicodeCollation =3D Uc; > + break; > + } > + > // > // Find the best matching matching language from the supported > languages > // of Unicode Collation2 protocol. > @@ -132,7 +138,9 @@ CommandInit( > if (Handles !=3D NULL) { > FreePool (Handles); > } > - FreePool (PlatformLang); > + if (PlatformLang !=3D NULL) { > + FreePool (PlatformLang); > + } > } >=20 > return (gUnicodeCollation =3D=3D NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS= ; > -- > 2.20.1 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. >=20 > 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] -=3D-=3D-=3D-=3D-=3D-=3D