]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellEnvVar.c
ShellPkg: Remove 'STATIC' from function declarations to avoid source level debugging...
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellEnvVar.c
index cd55fa907be69a6d3f0ac3df4fc066f3ffc3c10f..f40a867cc7ae564a6f4e607e36e4ed56205fab5f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   function declarations for shell environment functions.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, 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
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-\r
-#include <Guid/ShellVariableGuid.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-\r
-#include "ShellEnvVar.h"\r
-\r
+#include "Shell.h"\r
 \r
 /**\r
   Reports whether an environment variable is Volatile or Non-Volatile.\r
@@ -56,7 +45,7 @@ IsVolatileEnv (
                             &Size,\r
                             Buffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    Buffer = AllocatePool(Size);\r
+    Buffer = AllocateZeroPool(Size);\r
     ASSERT(Buffer != NULL);\r
     Status = gRT->GetVariable((CHAR16*)EnvVarName,\r
                               &gShellVariableGuid,\r
@@ -105,7 +94,7 @@ FreeEnvironmentVariableList(
   }\r
 \r
   for ( Node = (ENV_VAR_LIST*)GetFirstNode(List)\r
-      ; IsListEmpty(List)\r
+      ; !IsListEmpty(List)\r
       ; Node = (ENV_VAR_LIST*)GetFirstNode(List)\r
      ){\r
     ASSERT(Node != NULL);\r
@@ -123,8 +112,8 @@ FreeEnvironmentVariableList(
 /**\r
   Creates a list of all Shell-Guid-based environment variables.\r
 \r
-  @param[in,out] ListHead       The pointer to pointer to LIST ENTRY object for\r
-                                storing this list.\r
+  @param[in, out] ListHead       The pointer to pointer to LIST ENTRY object for\r
+                                 storing this list.\r
 \r
   @retval EFI_SUCCESS           the list was created sucessfully.\r
 **/\r
@@ -148,13 +137,18 @@ GetEnvironmentVariableList(
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
-  Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);\r
-  if (EFI_ERROR(Status)) {\r
-    return (Status);\r
+  if (gRT->Hdr.Revision >= EFI_2_00_SYSTEM_TABLE_REVISION) {\r
+    Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);\r
+    if (EFI_ERROR(Status)) {\r
+      return (Status);\r
+    }\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+    MaxVarSize = 16384;\r
   }\r
 \r
   NameSize = (UINTN)MaxVarSize;\r
-  VariableName = AllocatePool(NameSize);\r
+  VariableName = AllocateZeroPool(NameSize);\r
   if (VariableName == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
@@ -169,18 +163,31 @@ GetEnvironmentVariableList(
     }\r
     if (!EFI_ERROR(Status) && CompareGuid(&Guid, &gShellVariableGuid)){\r
       VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));\r
-      ValSize = 0;\r
-      Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);\r
-      if (Status == EFI_BUFFER_TOO_SMALL){\r
-        VarList->Val = AllocatePool(ValSize);\r
-        ASSERT(VarList->Val != NULL);\r
+      if (VarList == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+      } else {\r
+        ValSize = 0;\r
         Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);\r
-      }\r
-      if (!EFI_ERROR(Status)) {\r
-        VarList->Key = AllocatePool(StrSize(VariableName));\r
-        ASSERT(VarList->Key != NULL);\r
-        StrCpy(VarList->Key, VariableName);\r
-        InsertTailList(ListHead, &VarList->Link);\r
+        if (Status == EFI_BUFFER_TOO_SMALL){\r
+          VarList->Val = AllocateZeroPool(ValSize);\r
+          if (VarList->Val == NULL) {\r
+            SHELL_FREE_NON_NULL(VarList);\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+          } else {\r
+            Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);\r
+          }\r
+        }\r
+        if (!EFI_ERROR(Status) && VarList != NULL) {\r
+          VarList->Key = AllocateZeroPool(StrSize(VariableName));\r
+          if (VarList->Key == NULL) {\r
+            SHELL_FREE_NON_NULL(VarList->Val);\r
+            SHELL_FREE_NON_NULL(VarList);\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+          } else {\r
+            StrCpy(VarList->Key, VariableName);\r
+            InsertTailList(ListHead, &VarList->Link);\r
+          }\r
+        }\r
       }\r
     } // compare guid\r
   } // while\r
@@ -299,7 +306,7 @@ SetEnvironmentVariables(
       break;\r
     }\r
     ASSERT(StrStr(CurrentString, L"=") != NULL);\r
-    Node = AllocatePool(sizeof(ENV_VAR_LIST));\r
+    Node = AllocateZeroPool(sizeof(ENV_VAR_LIST));\r
     ASSERT(Node != NULL);\r
     Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));\r
     ASSERT(Node->Key != NULL);\r