/** @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
#include <Uefi.h>\r
+#include <ShellBase.h>\r
\r
#include <Guid/ShellVariableGuid.h>\r
\r
\r
#include "ShellEnvVar.h"\r
\r
-\r
/**\r
Reports whether an environment variable is Volatile or Non-Volatile.\r
\r
&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
/**\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
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
}\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
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