From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=hSsKup4R; spf=pass (domain: gmx.de, ip: 212.227.15.18, mailfrom: xypron.glpk@gmx.de) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by groups.io with SMTP; Thu, 09 May 2019 20:24:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1557458671; bh=s7W+3xXX9LqNw+oRpyWrFxNsggJF3wuu1x/d083UbPE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=hSsKup4RLYTrorHX4a9tKb2y+2/nTyOLLqGks/D6aU9asIhL5sP1aHxSWOGwmH2n5 i8MOY4pat3/VrByXa4Z5p9aQsVZeXoDzcy7ryATfVaWIcg5lTVdpPeokrsZxfQHD1Q NJA+LcppKC07wPh6tQ3WNR+LLhCtsSVTmZnA/N5k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([84.118.159.3]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MWSwU-1hEOGr0ZC6-00XbtE; Fri, 10 May 2019 05:24:31 +0200 From: "Heinrich Schuchardt" To: Zhichao Gao Cc: "devel @ edk2 . groups . io" , Jaben Carsey , Ray Ni , Leif Lindholm , Liming Gao , Heinrich Schuchardt Subject: [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak Date: Fri, 10 May 2019 05:24:19 +0200 Message-Id: <20190510032419.14540-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:f+ppet0bRPuCOxG+UrKRYpdWI8mRHcrNOi6h7UIJpPyKYXi1Eiz I/cgiCe3RNxZqhu04p7suZq2uP2fPduPGYsEK/eqdERfg0FkxQEWqtAqpNUwYY/ywljLZ0N u8REKAUkYh9NKj744gV8/abpLZP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j0wZ/loa Content-Transfer-Encoding: quoted-printable 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 (=3D NULL) in ShellCommandRegisterCommandName(). Furthermore CommandInit() is leaking PlatformLang if gUnicodeCollation !=3D 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 Reviewed-by: Zhichao Gao --- v3 resend as quoted-printable --- .../UefiShellCommandLib/UefiShellCommandLib.c | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/S= hellPkg/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;=0D CHAR8 *PlatformLang;=0D =0D - GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&Platfor= mLang, NULL);=0D - if (PlatformLang =3D=3D NULL) {=0D - return EFI_UNSUPPORTED;=0D - }=0D -=0D if (gUnicodeCollation =3D=3D NULL) {=0D +=0D + GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&Platf= ormLang, NULL);=0D +=0D Status =3D gBS->LocateHandleBuffer (=0D ByProtocol,=0D &gEfiUnicodeCollation2ProtocolGuid,=0D @@ -113,6 +111,14 @@ CommandInit( continue;=0D }=0D =0D + //=0D + // Without clue provided use the first Unicode Collation2 protocol.= =0D + //=0D + if (PlatformLang =3D=3D NULL) {=0D + gUnicodeCollation =3D Uc;=0D + break;=0D + }=0D +=0D //=0D // Find the best matching matching language from the supported langu= ages=0D // of Unicode Collation2 protocol.=0D @@ -132,7 +138,9 @@ CommandInit( if (Handles !=3D NULL) {=0D FreePool (Handles);=0D }=0D - FreePool (PlatformLang);=0D + if (PlatformLang !=3D NULL) {=0D + FreePool (PlatformLang);=0D + }=0D }=0D =0D return (gUnicodeCollation =3D=3D NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;= =0D --=20 2.20.1