Emulation Variable services operate on the runtime volatile memory.\r
The nonvolatile variable space doesn't exist.\r
\r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
// The end of variable store\r
//\r
- return (VARIABLE_HEADER *) HEADER_ALIGN (VolHeader + 1);\r
+ return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VolHeader + VolHeader->Size);\r
}\r
\r
/**\r
ASSERT (gVariableInfo != NULL);\r
\r
CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);\r
- gVariableInfo->Name = AllocatePool (StrSize (VariableName));\r
+ gVariableInfo->Name = AllocateZeroPool (StrSize (VariableName));\r
ASSERT (gVariableInfo->Name != NULL);\r
- StrCpy (gVariableInfo->Name, VariableName);\r
+ StrnCpy (gVariableInfo->Name, VariableName, StrLen (VariableName));\r
gVariableInfo->Volatile = Volatile;\r
\r
gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
ASSERT (Entry->Next != NULL);\r
\r
CopyGuid (&Entry->Next->VendorGuid, VendorGuid);\r
- Entry->Next->Name = AllocatePool (StrSize (VariableName));\r
+ Entry->Next->Name = AllocateZeroPool (StrSize (VariableName));\r
ASSERT (Entry->Next->Name != NULL);\r
- StrCpy (Entry->Next->Name, VariableName);\r
+ StrnCpy (Entry->Next->Name, VariableName, StrLen (VariableName));\r
Entry->Next->Volatile = Volatile;\r
}\r
\r
if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
return EFI_INVALID_PARAMETER;\r
}\r
+\r
+ \r
+ if ((UINTN)(~0) - DataSize < StrSize(VariableName)){\r
+ //\r
+ // Prevent whole variable size overflow \r
+ // \r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
//\r
// The size of the VariableName, including the Unicode Null in bytes plus\r
// the DataSize is limited to maximum size of PcdGet32 (PcdMaxHardwareErrorVariableSize)\r
// bytes for HwErrRec, and PcdGet32 (PcdMaxVariableSize) bytes for the others.\r
//\r
if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
- if ((DataSize > PcdGet32 (PcdMaxHardwareErrorVariableSize)) || \r
- (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > PcdGet32 (PcdMaxHardwareErrorVariableSize))) {\r
+ if (StrSize (VariableName) + DataSize > PcdGet32 (PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
//\r
// The size of the VariableName, including the Unicode Null in bytes plus\r
// the DataSize is limited to maximum size of PcdGet32 (PcdMaxVariableSize) bytes.\r
//\r
- if ((DataSize > PcdGet32 (PcdMaxVariableSize)) ||\r
- (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > PcdGet32 (PcdMaxVariableSize))) {\r
+ if (StrSize (VariableName) + DataSize > PcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER)) {\r
return EFI_INVALID_PARAMETER;\r
} \r
}\r