[edk2] [PATCH v2] ShellPkg/set: Fix EfiShellSetEnv to use case sensitive compare

Ruiyu Ni posted 1 patch 5 years, 7 months ago
Failed in applying to current master (apply log)
ShellPkg/Application/Shell/ShellProtocol.c | 39 +++++++-----------------------
1 file changed, 9 insertions(+), 30 deletions(-)
[edk2] [PATCH v2] ShellPkg/set: Fix EfiShellSetEnv to use case sensitive compare
Posted by Ruiyu Ni 5 years, 7 months ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=777

Per Shell spec, the environment variable has a case-sensitive name.
But today's implementation of EfiShellSetEnv() compares the
environment variable name case insensitively, which causes variable
like "CWD" cannot be set due to "cwd" is pre-defined variable.

The patch fixes this issue.

The EfiShellGetEnv() doesn't have such issue because it will
call into ShellFindEnvVarInList() which uses StrCmp().

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Jim Dailey <jim_dailey@dell.com>
---
 ShellPkg/Application/Shell/ShellProtocol.c | 39 +++++++-----------------------
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index f2ca2029e3..9e9e6dc052 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -2924,36 +2924,15 @@ EfiShellSetEnv(
   //
   // Make sure we dont 'set' a predefined read only variable
   //
-  if (gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"cwd") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"Lasterror") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"profiles") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"uefishellsupport") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"uefishellversion") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"uefiversion") == 0
-    ||(!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest &&
-      gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        (CHAR16*)mNoNestingEnvVarName) == 0)
-       ){
+  if ((StrCmp (Name, L"cwd") == 0) ||
+      (StrCmp (Name, L"lasterror") == 0) ||
+      (StrCmp (Name, L"profiles") == 0) ||
+      (StrCmp (Name, L"uefishellsupport") == 0) ||
+      (StrCmp (Name, L"uefishellversion") == 0) ||
+      (StrCmp (Name, L"uefiversion") == 0) ||
+      (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest &&
+       StrCmp (Name, mNoNestingEnvVarName) == 0)
+     ) {
     return (EFI_INVALID_PARAMETER);
   }
   return (InternalEfiShellSetEnv(Name, Value, Volatile));
-- 
2.16.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v2] ShellPkg/set: Fix EfiShellSetEnv to use case sensitive compare
Posted by Jim.Dailey@dell.com 5 years, 7 months ago
Reviewed-by: Jim Dailey <jim_dailey@dell.com>

-----Original Message-----
From: Ruiyu Ni [mailto:ruiyu.ni@intel.com] 
Sent: Wednesday, August 8, 2018 12:04 AM
To: edk2-devel@lists.01.org
Cc: Jaben Carsey; Dailey, Jim
Subject: [PATCH v2] ShellPkg/set: Fix EfiShellSetEnv to use case sensitive compare

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=777

Per Shell spec, the environment variable has a case-sensitive name.
But today's implementation of EfiShellSetEnv() compares the
environment variable name case insensitively, which causes variable
like "CWD" cannot be set due to "cwd" is pre-defined variable.

The patch fixes this issue.

The EfiShellGetEnv() doesn't have such issue because it will
call into ShellFindEnvVarInList() which uses StrCmp().

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Jim Dailey <jim_dailey@dell.com>
---
 ShellPkg/Application/Shell/ShellProtocol.c | 39 +++++++-----------------------
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index f2ca2029e3..9e9e6dc052 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -2924,36 +2924,15 @@ EfiShellSetEnv(
   //
   // Make sure we dont 'set' a predefined read only variable
   //
-  if (gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"cwd") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"Lasterror") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"profiles") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"uefishellsupport") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"uefishellversion") == 0
-    ||gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        L"uefiversion") == 0
-    ||(!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest &&
-      gUnicodeCollation->StriColl(
-        gUnicodeCollation,
-        (CHAR16*)Name,
-        (CHAR16*)mNoNestingEnvVarName) == 0)
-       ){
+  if ((StrCmp (Name, L"cwd") == 0) ||
+      (StrCmp (Name, L"lasterror") == 0) ||
+      (StrCmp (Name, L"profiles") == 0) ||
+      (StrCmp (Name, L"uefishellsupport") == 0) ||
+      (StrCmp (Name, L"uefishellversion") == 0) ||
+      (StrCmp (Name, L"uefiversion") == 0) ||
+      (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest &&
+       StrCmp (Name, mNoNestingEnvVarName) == 0)
+     ) {
     return (EFI_INVALID_PARAMETER);
   }
   return (InternalEfiShellSetEnv(Name, Value, Volatile));
-- 
2.16.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel