]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellEnvVar.c
ShellPkg: Clean up source files
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellEnvVar.c
index 6d8c79b4ca6a21c42a8c597d215d58493e7fa6fa..663276454273d7cb239e898134fa68ddbd85264b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   function declarations for shell environment functions.\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -143,9 +143,9 @@ GetEnvironmentVariableList(
   if (ListHead == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
-  \r
+\r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   ValBufferSize = INIT_DATA_BUFFER_SIZE;\r
   NameBufferSize = INIT_NAME_BUFFER_SIZE;\r
   VariableName = AllocateZeroPool(NameBufferSize);\r
@@ -171,14 +171,17 @@ GetEnvironmentVariableList(
       NameSize = NameBufferSize;\r
       Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);\r
     }\r
-    \r
+\r
     if (!EFI_ERROR(Status) && CompareGuid(&Guid, &gShellVariableGuid)){\r
       VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));\r
       if (VarList == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
       } else {\r
         ValSize = ValBufferSize;\r
-        VarList->Val = AllocateZeroPool(ValSize);\r
+        //\r
+        // We need another CHAR16 to save '\0' in VarList->Val.\r
+        //\r
+        VarList->Val = AllocateZeroPool (ValSize + sizeof (CHAR16));\r
         if (VarList->Val == NULL) {\r
             SHELL_FREE_NON_NULL(VarList);\r
             Status = EFI_OUT_OF_RESOURCES;\r
@@ -188,13 +191,16 @@ GetEnvironmentVariableList(
         if (Status == EFI_BUFFER_TOO_SMALL){\r
           ValBufferSize = ValSize > ValBufferSize * 2 ? ValSize : ValBufferSize * 2;\r
           SHELL_FREE_NON_NULL (VarList->Val);\r
-          VarList->Val = AllocateZeroPool(ValBufferSize);\r
+          //\r
+          // We need another CHAR16 to save '\0' in VarList->Val.\r
+          //\r
+          VarList->Val = AllocateZeroPool (ValBufferSize + sizeof (CHAR16));\r
           if (VarList->Val == NULL) {\r
             SHELL_FREE_NON_NULL(VarList);\r
             Status = EFI_OUT_OF_RESOURCES;\r
             break;\r
           }\r
-          \r
+\r
           ValSize = ValBufferSize;\r
           Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);\r
         }\r
@@ -272,7 +278,7 @@ SetEnvironmentVariableList(
       ; !IsNull(ListHead, &Node->Link)\r
       ; Node = (ENV_VAR_LIST*)GetNextNode(ListHead, &Node->Link)\r
      ){\r
-    Size = StrSize(Node->Val);\r
+    Size = StrSize (Node->Val) - sizeof (CHAR16);\r
     if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) {\r
       Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(Node->Key, Size, Node->Val);\r
     } else {\r
@@ -342,8 +348,8 @@ SetEnvironmentVariables(
     //\r
     // Copy the string into the Key, leaving the last character allocated as NULL to terminate\r
     //\r
-    StrnCpyS( Node->Key, \r
-              StrStr(CurrentString, L"=") - CurrentString + 1, \r
+    StrnCpyS( Node->Key,\r
+              StrStr(CurrentString, L"=") - CurrentString + 1,\r
               CurrentString,\r
               StrStr(CurrentString, L"=") - CurrentString\r
               );\r
@@ -407,7 +413,7 @@ ShellFindEnvVarInList (
   )\r
 {\r
   ENV_VAR_LIST      *Node;\r
-  \r
+\r
   if (Key == NULL || Value == NULL || ValueSize == NULL) {\r
     return SHELL_INVALID_PARAMETER;\r
   }\r
@@ -453,7 +459,7 @@ ShellAddEnvVarToList (
   ENV_VAR_LIST      *Node;\r
   CHAR16            *LocalKey;\r
   CHAR16            *LocalValue;\r
-  \r
+\r
   if (Key == NULL || Value == NULL || ValueSize == 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -505,7 +511,7 @@ ShellAddEnvVarToList (
   Remove a specified environment variable in gShellEnvVarList.\r
 \r
   @param Key        The name of the environment variable.\r
-  \r
+\r
   @retval EFI_SUCCESS       The command executed successfully.\r
   @retval EFI_NOT_FOUND     The environment variable is not found in\r
                             gShellEnvVarList.\r
@@ -540,7 +546,7 @@ ShellRemvoeEnvVarFromList (
 /**\r
   Initialize the gShellEnvVarList and cache all Shell-Guid-based environment\r
   variables.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 ShellInitEnvVarList (\r