]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellEnvVar.c
Add missing braces around initializer.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellEnvVar.c
index cd55fa907be69a6d3f0ac3df4fc066f3ffc3c10f..a4bd6a61797c5a9bee45035be2af3d44ea01bcb0 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
@@ -13,6 +13,7 @@
 **/\r
 \r
 #include <Uefi.h>\r
+#include <ShellBase.h>\r
 \r
 #include <Guid/ShellVariableGuid.h>\r
 \r
@@ -24,7 +25,6 @@
 \r
 #include "ShellEnvVar.h"\r
 \r
-\r
 /**\r
   Reports whether an environment variable is Volatile or Non-Volatile.\r
 \r
@@ -56,7 +56,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
@@ -123,8 +123,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 +148,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 +174,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 +317,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