From nobody Fri Nov 1 10:36:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1516957668103150.10334296613541; Fri, 26 Jan 2018 01:07:48 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 73EAD222A334D; Fri, 26 Jan 2018 01:02:15 -0800 (PST) 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 BA7A92222C24C for ; Fri, 26 Jan 2018 01:02:13 -0800 (PST) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jan 2018 01:07:43 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.19]) by orsmga007.jf.intel.com with ESMTP; 26 Jan 2018 01:07:43 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,415,1511856000"; d="scan'208";a="12765729" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Fri, 26 Jan 2018 17:07:38 +0800 Message-Id: <20180126090739.14188-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20180126090739.14188-1-ruiyu.ni@intel.com> References: <20180126090739.14188-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben@ml01.01.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Original code locates the first UnicodeCollation instance in DXE Core protocol database. It's not correct considering multiple UnicodeCollation instances exist in system. The patch changes logic to find the one that matches the current system language. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey + Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
=20 @@ -72,14 +72,70 @@ CommandInit( VOID ) { - EFI_STATUS Status; + UINTN NumHandles; + EFI_HANDLE *Handles; + EFI_UNICODE_COLLATION_PROTOCOL *Uc; + CHAR8 *BestLanguage; + UINTN Index; + EFI_STATUS Status; + CHAR8 *PlatformLang; + =20 + GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&Platfor= mLang, NULL); + if (PlatformLang =3D=3D NULL) { + return EFI_UNSUPPORTED; + } + if (gUnicodeCollation =3D=3D NULL) { - Status =3D gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NUL= L, (VOID**)&gUnicodeCollation); - if (EFI_ERROR(Status)) { - return (EFI_DEVICE_ERROR); + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiUnicodeCollation2ProtocolGuid, + NULL, + &NumHandles, + &Handles + ); + if (EFI_ERROR (Status)) { + NumHandles =3D 0; + Handles =3D NULL; } + for (Index =3D 0; Index < NumHandles; Index++) { + // + // Open Unicode Collation Protocol + // + Status =3D gBS->OpenProtocol ( + Handles[Index], + &gEfiUnicodeCollation2ProtocolGuid, + (VOID **) &Uc, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Find the best matching matching language from the supported langu= ages + // of Unicode Collation2 protocol.=20 + // + BestLanguage =3D GetBestLanguage ( + Uc->SupportedLanguages, + FALSE, + PlatformLang, + NULL + ); + if (BestLanguage !=3D NULL) { + FreePool (BestLanguage); + gUnicodeCollation =3D Uc; + break; + } + } + if (Handles !=3D NULL) { + FreePool (Handles); + } + FreePool (PlatformLang); } - return (EFI_SUCCESS); + + return (gUnicodeCollation =3D=3D NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS; } =20 /** @@ -112,11 +168,9 @@ ShellCommandLibConstructor ( mProfileListSize =3D 0; mProfileList =3D NULL; =20 - if (gUnicodeCollation =3D=3D NULL) { - Status =3D gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NUL= L, (VOID**)&gUnicodeCollation); - if (EFI_ERROR(Status)) { - return (EFI_DEVICE_ERROR); - } + Status =3D CommandInit (); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; } =20 return (RETURN_SUCCESS); diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h b/S= hellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h index b998656b4e..bcfde60c26 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h @@ -1,7 +1,7 @@ /** @file Provides interface to shell internal functions for shell commands. =20 - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -19,6 +19,7 @@ #include =20 #include +#include =20 #include #include --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Fri Nov 1 10:36:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1516957670252300.8900807544795; Fri, 26 Jan 2018 01:07:50 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CB7D8222A3369; Fri, 26 Jan 2018 01:02:17 -0800 (PST) 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 9B3DC21E256BE for ; Fri, 26 Jan 2018 01:02:14 -0800 (PST) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jan 2018 01:07:44 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.19]) by orsmga007.jf.intel.com with ESMTP; 26 Jan 2018 01:07:44 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,415,1511856000"; d="scan'208";a="12765736" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Fri, 26 Jan 2018 17:07:39 +0800 Message-Id: <20180126090739.14188-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20180126090739.14188-1-ruiyu.ni@intel.com> References: <20180126090739.14188-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/2] ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey --- ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c | 4 +- ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c | 4 +- .../Library/UefiShellLevel2CommandsLib/TimeDate.c | 6 +- .../UefiShellLevel2CommandsLib.c | 65 +++++++++++-------= ---- .../UefiShellLevel2CommandsLib.h | 15 ++--- 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Li= brary/UefiShellLevel2CommandsLib/Cd.c index 9ae81763f7..d5dc9804d4 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c @@ -3,7 +3,7 @@ =20 (C) Copyright 2016 Hewlett Packard Enterprise Development LP
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, 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 @@ -102,7 +102,7 @@ IsCurrentFileSystem ( if (((UINTN) Splitter1 - (UINTN) FullPath) !=3D ((UINTN) Splitter2 - (UI= NTN) Cwd)) { return FALSE; } else { - if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / = sizeof (CHAR16)) =3D=3D NULL) { + if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / = sizeof (CHAR16)) =3D=3D 0) { return TRUE; } else { return FALSE; diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Li= brary/UefiShellLevel2CommandsLib/Cp.c index b8f6d310f6..ae7528ddcf 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -2,7 +2,7 @@ Main file for cp shell level 2 function. =20 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, 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 @@ -510,7 +510,7 @@ ValidateAndCopyFiles( =20 if ( !EFI_ERROR(ShellIsDirectory(Node->FullName)) && !EFI_ERROR(ShellIsDirectory(DestPath)) - && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) =3D=3D NULL + && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) =3D=3D 0 ){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShel= lLevel2HiiHandle, L"cp"); =20 ShellStatus =3D SHELL_INVALID_PARAMETER; diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c b/Shell= Pkg/Library/UefiShellLevel2CommandsLib/TimeDate.c index 5383cffe87..0b7551a239 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c @@ -2,7 +2,7 @@ Main file for time, timezone, and date shell level 2 and shell level 3 f= unctions. =20 (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, 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 @@ -550,7 +550,7 @@ ShellCommandRunTime ( // perform level 3 operation here. // if ((TempLocation =3D ShellCommandLineGetValue(Package, L"-tz"))= !=3D NULL) { - if (StrniCmp (TempLocation, L"_local", StrLen (TempLocation)) = =3D=3D NULL) { + if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)T= empLocation, L"_local") =3D=3D 0) { Tz =3D EFI_UNSPECIFIED_TIMEZONE; } else if (TempLocation[0] =3D=3D L'-') { =20 @@ -713,7 +713,7 @@ CheckAndSetTimeZone ( return (SHELL_INVALID_PARAMETER); } =20 - if (StrniCmp (TimeZoneString, L"_local", StrLen (TimeZoneString)) =3D=3D= NULL) { + if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TimeZoneStr= ing, L"_local") =3D=3D 0) { Status =3D gRT->GetTime (&TheTime, NULL); if (EFI_ERROR (Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN),= gShellLevel2HiiHandle, L"gRT->GetTime", Status); diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Com= mandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Com= mandsLib.c index e9ce631892..36bc3552b5 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLi= b.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLi= b.c @@ -22,7 +22,7 @@ * functions are non-interactive only =20 Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, 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 @@ -260,19 +260,6 @@ VerifyIntermediateDirectories ( return (Status); } =20 -/** - Be lazy and borrow from baselib. - - @param[in] Char The character to convert to upper case. - - @return Char as an upper case character. -**/ -CHAR16 -EFIAPI -InternalCharToUpper ( - IN CHAR16 Char - ); - /** String comparison without regard to case for a limited number of charact= ers. =20 @@ -280,31 +267,47 @@ InternalCharToUpper ( @param[in] Target The second item to compare. @param[in] Count How many characters to compare. =20 - @retval NULL Source and Target are identical strings without regard to c= ase. - @return The location in Source where there is a difference. + @retval 0 Source and Target are identical strings without regard to c= ase. + @retval !=3D0 Source is not identical to Target. + =20 **/ -CONST CHAR16* +INTN StrniCmp( IN CONST CHAR16 *Source, IN CONST CHAR16 *Target, IN CONST UINTN Count ) { - UINTN LoopCount; - CHAR16 Char1; - CHAR16 Char2; - - ASSERT(Source !=3D NULL); - ASSERT(Target !=3D NULL); - - for (LoopCount =3D 0 ; LoopCount < Count ; LoopCount++) { - Char1 =3D InternalCharToUpper(Source[LoopCount]); - Char2 =3D InternalCharToUpper(Target[LoopCount]); - if (Char1 !=3D Char2) { - return (&Source[LoopCount]); - } + CHAR16 *SourceCopy; + CHAR16 *TargetCopy; + UINTN SourceLength; + UINTN TargetLength; + INTN Result; + + if (Count =3D=3D 0) { + return 0; + } + + SourceLength =3D StrLen (Source); + TargetLength =3D StrLen (Target); + SourceLength =3D MIN (SourceLength, Count); + TargetLength =3D MIN (TargetLength, Count); + SourceCopy =3D AllocateCopyPool ((SourceLength + 1) * sizeof (CHAR16), S= ource); + if (SourceCopy =3D=3D NULL) { + return -1; + } + TargetCopy =3D AllocateCopyPool ((TargetLength + 1) * sizeof (CHAR16), T= arget); + if (TargetCopy =3D=3D NULL) { + FreePool (SourceCopy); + return -1; } - return (NULL); + =20 + SourceCopy[SourceLength] =3D L'\0'; + TargetCopy[TargetLength] =3D L'\0'; + Result =3D gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, T= argetCopy); + FreePool (SourceCopy); + FreePool (TargetCopy); + return Result; } =20 =20 diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Com= mandsLib.h b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Com= mandsLib.h index 857487fd80..fef6adc3e1 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLi= b.h +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLi= b.h @@ -280,16 +280,17 @@ VerifyIntermediateDirectories ( ); =20 /** - CaseInsensitive length limited string comparison. + String comparison without regard to case for a limited number of charact= ers. =20 - @param[in] Source Pointer to first string. - @param[in] Target Pointer to second string. - @param[in] Count Number of characters to compare. + @param[in] Source The first item to compare. + @param[in] Target The second item to compare. + @param[in] Count How many characters to compare. =20 - @retval 0 The strings are the same. - @return non-zero if the strings are different. + @retval 0 Source and Target are identical strings without regard to c= ase. + @retval !=3D0 Source is not identical to Target. + =20 **/ -CONST CHAR16* +INTN StrniCmp( IN CONST CHAR16 *Source, IN CONST CHAR16 *Target, --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel