/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
- // Put break point in module that contained the error.\r
+ // Put dead loop in module that contained the error.\r
//\r
EFI_DEADLOOP ();\r
}\r
/*++\r
\r
-Copyright (c) 2004 - 2005, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
+ //\r
+ // Initialize 'LogHob' to NULL before usage.\r
+ //\r
+ LogHob = NULL;\r
+\r
if (Ticker != 0) {\r
TimerValue = Ticker;\r
} else {\r
EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);\r
do {\r
Status = GetNextGuidHob (&HobList, &gEfiPeiPerformanceHobGuid, (VOID **) &LogHob, NULL);\r
- if (EFI_ERROR (Status)) {\r
+ if (EFI_ERROR (Status) || (LogHob == NULL)) {\r
+ //\r
+ // Failed to get HOB for ProtocolGuid.\r
+ //\r
break;\r
}\r
\r
/*++\r
\r
-Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
if (GraphicsOutput != NULL) {\r
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
- } else {\r
+ } else if (UgaDraw != NULL) {\r
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
if (EFI_ERROR (Status)) {\r
return EFI_UNSUPPORTED;\r
}\r
+ } else {\r
+ return EFI_UNSUPPORTED;\r
}\r
\r
Instance = 0;\r
/*++\r
\r
-Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
Returns: \r
\r
- EFI_SUCCESS - success\r
- EFI_OUT_OF_RESOURCES - out of resources\r
+ Length of string printed to the console\r
\r
--*/\r
{\r
//\r
Buffer = EfiLibAllocateZeroPool (0x10000);\r
if (Buffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ return 0;\r
}\r
\r
if (GraphicsOutput != NULL) {\r
EfiLibSafeFreePool (Blt);\r
EfiLibSafeFreePool (FontInfo);\r
#else\r
- gBS->FreePool (LineBuffer);\r
+ EfiLibSafeFreePool (LineBuffer);\r
#endif \r
gBS->FreePool (Buffer);\r
- return Status;\r
+ \r
+ if (EFI_ERROR (Status)) {\r
+ return 0;\r
+ }\r
+\r
+ return BufferLen;\r
}\r
\r
\r
(VOID**)&UgaDraw\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ if (EFI_ERROR (Status) || (UgaDraw == NULL)) {\r
+ return 0;\r
}\r
}\r
\r
+ Sto = NULL;\r
Status = gBS->HandleProtocol (\r
Handle,\r
&gEfiSimpleTextOutProtocolGuid,\r
(VOID**)&Sto\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ if (EFI_ERROR (Status) || (Sto == NULL)) {\r
+ return 0;\r
}\r
\r
return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
/*++\r
\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINTN Index;\r
- CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
- CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
+ CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
+ CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
\r
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {\r
UnicodeFormat[Index] = (CHAR16) FormatString[Index];\r
\r
UnicodeFormat[Index] = '\0';\r
\r
- Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);\r
+ Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);\r
\r
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {\r
Buffer[Index] = (CHAR8) UnicodeResult[Index];\r
/*++\r
\r
-Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
if (GraphicsOutput != NULL) {\r
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
- } else {\r
+ } else if (UgaDraw != NULL) {\r
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
if (EFI_ERROR (Status)) {\r
return EFI_UNSUPPORTED;\r
}\r
+ } else {\r
+ return EFI_UNSUPPORTED;\r
}\r
\r
Instance = 0;\r
/*++\r
\r
-Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
Returns: \r
\r
- EFI_SUCCESS - success\r
- EFI_OUT_OF_RESOURCES - out of resources\r
+ Length of string printed to the console\r
\r
--*/\r
{\r
//\r
Buffer = EfiLibAllocateZeroPool (0x10000);\r
if (Buffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ return 0;\r
}\r
\r
if (GraphicsOutput != NULL) {\r
EfiLibSafeFreePool (Blt);\r
EfiLibSafeFreePool (FontInfo);\r
#else\r
- gBS->FreePool (LineBuffer);\r
+ EfiLibSafeFreePool (LineBuffer);\r
#endif \r
gBS->FreePool (Buffer);\r
- return Status;\r
+ \r
+ if (EFI_ERROR (Status)) {\r
+ return 0;\r
+ }\r
+\r
+ return BufferLen;\r
}\r
\r
\r
(VOID **) &UgaDraw\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ if (EFI_ERROR (Status) || (UgaDraw != NULL)) {\r
+ return 0;\r
}\r
}\r
\r
+ Sto = NULL;\r
Status = gBS->HandleProtocol (\r
Handle,\r
&gEfiSimpleTextOutProtocolGuid,\r
(VOID **) &Sto\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ if (EFI_ERROR (Status) || (Sto != NULL)) {\r
+ return 0;\r
}\r
\r
return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
/*++\r
\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINTN Index;\r
- CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
- CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
+ CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
+ CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
\r
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {\r
UnicodeFormat[Index] = (CHAR16) FormatString[Index];\r
\r
UnicodeFormat[Index] = '\0';\r
\r
- Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);\r
+ Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);\r
\r
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {\r
Buffer[Index] = (CHAR8) UnicodeResult[Index];\r
/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
EFI_STATUS Status;\r
VOID *HobStart2;\r
\r
+ //\r
+ // Initialize 'Buffer' to NULL before usage\r
+ //\r
+ Buffer = NULL;\r
HobStart2 = HobStart;\r
Status = GetNextGuidHob (\r
&HobStart2,\r
&Buffer,\r
&BufferSize\r
);\r
-\r
+ if (EFI_ERROR (Status) || (Buffer == NULL)) {\r
+ //\r
+ // Failed to get HOB for gPalEntryHob\r
+ //\r
+ return EFI_NOT_FOUND;\r
+ }\r
*PalEntry = *((EFI_PHYSICAL_ADDRESS *) Buffer);\r
- return Status;\r
+ return EFI_SUCCESS;\r
}\r
\r
\r
EFI_STATUS Status;\r
VOID *HobStart2;\r
\r
+ //\r
+ // Initialize 'Buffer' to NULL before usage\r
+ //\r
+ Buffer = NULL;\r
HobStart2 = HobStart;\r
Status = GetNextGuidHob (\r
&HobStart2,\r
&Buffer,\r
&BufferSize\r
);\r
+ if (EFI_ERROR (Status) || (Buffer == NULL)) {\r
+ //\r
+ // Failed to get HOB for gEfiIoBaseHobGuid\r
+ //\r
+ return EFI_NOT_FOUND;\r
+ }\r
\r
*IoPortSpaceAddress = *((EFI_PHYSICAL_ADDRESS *) Buffer);\r
- return Status;\r
+ return EFI_SUCCESS;\r
}\r
/*++\r
\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINTN Index;\r
- CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
- CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
+ CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
+ CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
\r
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {\r
UnicodeFormat[Index] = (CHAR16) FormatString[Index];\r
\r
UnicodeFormat[Index] = '\0';\r
\r
- Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);\r
+ Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);\r
\r
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {\r
Buffer[Index] = (CHAR8) UnicodeResult[Index];\r
/*++\r
\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINTN Index;\r
- CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
- CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
+ CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
+ CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];\r
\r
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {\r
UnicodeFormat[Index] = (CHAR16) FormatString[Index];\r
\r
UnicodeFormat[Index] = '\0';\r
\r
- Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);\r
+ Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);\r
\r
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {\r
Buffer[Index] = (CHAR8) UnicodeResult[Index];\r
/*++\r
\r
-Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2010, 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
Status = HiiDatabase->ExportPackageLists (HiiDatabase, Handle, &BufferSize, HiiPackageList);\r
}\r
+ if (HiiPackageList == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
if (EFI_ERROR (Status)) {\r
+ gBS->FreePool (HiiPackageList);\r
return Status;\r
}\r
\r
/*++\r
\r
-Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2010, 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
LocateHiiProtocols ();\r
\r
Languages = GetSupportedLanguages (PackageList);\r
+ if (Languages == NULL) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
\r
LangStrings = Languages;\r
while (*LangStrings != 0) {\r
LocateHiiProtocols ();\r
\r
Languages = GetSupportedLanguages (PackageList);\r
+ if (Languages == NULL) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
\r
LangStrings = Languages;\r
while (*LangStrings != 0) {\r
/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
// the optional header to verify a desired directory entry is there.\r
//\r
\r
- if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
+ if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC && RelocDir->Size > 0) {\r
RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress);\r
RelocBaseEnd = PeCoffLoaderImageAddress (\r
ImageContext,\r
RelocDir->VirtualAddress + RelocDir->Size - 1\r
);\r
+ if ((RelocBase == NULL) || (RelocBaseEnd == NULL)) {\r
+ //\r
+ // If the base start or end address resolved to 0, then fail.\r
+ //\r
+ return RETURN_LOAD_ERROR;\r
+ }\r
} else {\r
//\r
// Set base and end to bypass processing below.\r
// Find the relocation block\r
//\r
RelocDir = &Hdr.Te->DataDirectory[0];\r
- RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
- ImageContext->ImageAddress +\r
- RelocDir->VirtualAddress +\r
- sizeof(EFI_TE_IMAGE_HEADER) -\r
- Hdr.Te->StrippedSize\r
- );\r
- RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
+ if (RelocDir->Size > 0) {\r
+ RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
+ ImageContext->ImageAddress +\r
+ RelocDir->VirtualAddress +\r
+ sizeof(EFI_TE_IMAGE_HEADER) -\r
+ Hdr.Te->StrippedSize\r
+ );\r
+ RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
+ } else {\r
+ //\r
+ // Set base and end to bypass processing below.\r
+ //\r
+ RelocBase = NULL;\r
+ RelocBaseEnd = NULL;\r
+ }\r
}\r
\r
//\r
RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);\r
if (!(ImageContext->IsTeImage)) {\r
FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);\r
+\r
+ if (FixupBase == NULL) {\r
+ //\r
+ // If the FixupBase address resolved to 0, then fail.\r
+ //\r
+ return RETURN_LOAD_ERROR;\r
+ }\r
} else {\r
FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
RelocBase->VirtualAddress +\r
/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINT16 WordOfStart;\r
UINT16 WordOfCount;\r
\r
-\r
- for (Index = 1; Index <= 16; Index++) {\r
+ //\r
+ // TableBits should not be greater than 16.\r
+ //\r
+ if (TableBits >= (sizeof (Count)/sizeof (UINT16))) {\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
+ \r
+ //\r
+ // Initialize Count array starting from Index 0, as there is a possibility of Count array being uninitialized.\r
+ //\r
+ for (Index = 0; Index <= 16; Index++) {\r
Count[Index] = 0;\r
}\r
\r
for (Index = 0; Index < NumOfChar; Index++) {\r
- Count[BitLen[Index]]++;\r
+ //\r
+ // Count array index should not be greater than or equal to its size.\r
+ //\r
+ if (BitLen[Index] < (sizeof (Count)/sizeof (UINT16))) {\r
+ Count[BitLen[Index]]++;\r
+ } else {\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
}\r
\r
+ Start[0] = 0;\r
Start[1] = 0;\r
\r
for (Index = 1; Index <= 16; Index++) {\r
for (Char = 0; Char < NumOfChar; Char++) {\r
\r
Len = BitLen[Char];\r
- if (Len == 0) {\r
+ if (Len == 0 || Len >= 17) {\r
continue;\r
}\r
\r
Index = (UINT16) (Len - TableBits);\r
\r
while (Index != 0) {\r
- if (*Pointer == 0) {\r
+ //\r
+ // Avail should be lesser than size of mRight and mLeft to prevent buffer overflow.\r
+ //\r
+ if ((*Pointer == 0) && (Avail < sizeof (Sd->mRight)/sizeof (UINT16)) && (Avail < sizeof (Sd->mLeft)/sizeof (UINT16))) {\r
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
*Pointer = Avail++;\r
}\r
\r
- if (Index3 & Mask) {\r
+ //\r
+ // *Pointer should be lesser than size of mRight and mLeft to prevent buffer overflow.\r
+ //\r
+ if ((Index3 & Mask) && (*Pointer < (sizeof (Sd->mRight)/sizeof (UINT16)))) {\r
Pointer = &Sd->mRight[*Pointer];\r
- } else {\r
+ } else if (*Pointer < (sizeof (Sd->mLeft)/sizeof (UINT16))) {\r
Pointer = &Sd->mLeft[*Pointer];\r
}\r
\r
//\r
Number = (UINT16) GetBits (Sd, nbit);\r
\r
+ if ((Number > sizeof (Sd->mPTLen)) || (nn > sizeof (Sd->mPTLen))) {\r
+ //\r
+ // Fail if Number or nn is greater than size of mPTLen\r
+ //\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
+\r
if (Number == 0) {\r
//\r
// This represents only Huffman code used\r
if (Index == Special) {\r
CharC = (UINT16) GetBits (Sd, 2);\r
while ((INT16) (--CharC) >= 0) {\r
+ if (Index >= sizeof (Sd->mPTLen)) {\r
+ //\r
+ // Fail if Index is greater than or equal to mPTLen\r
+ //\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
Sd->mPTLen[Index++] = 0;\r
}\r
}\r
/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
do {\r
GuidHob = (EFI_HOB_GUID_TYPE *)GlueGetNextGuidHob (&gEfiPeiPerformanceHobGuid, &HobList);\r
+ if (GuidHob == NULL) {\r
+ break;\r
+ }\r
LogHob = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)GET_GUID_HOB_DATA (GuidHob);\r
\r
for (Index = 0; Index < LogHob->NumberOfEntries; Index++) {\r
/*++\r
\r
-Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));\r
ASSERT (HiiPackages != NULL);\r
+ if (HiiPackages == NULL) {\r
+ return NULL;\r
+ }\r
\r
HiiPackages->GuidId = (EFI_GUID *) Guid;\r
HiiPackages->NumberOfPackages = NumberOfPackages;\r
/*++\r
\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINT16 NextCode;\r
UINT16 Mask;\r
\r
- for (Index = 1; Index <= 16; Index++) {\r
+ //\r
+ // TableBits should not be greater than 16.\r
+ //\r
+ if (TableBits >= (sizeof (Count)/sizeof (UINT16))) {\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
+ \r
+ //\r
+ // Initialize Count array starting from Index 0, as there is a possibility of Count array being uninitialized.\r
+ //\r
+ for (Index = 0; Index <= 16; Index++) {\r
Count[Index] = 0;\r
}\r
\r
for (Index = 0; Index < NumOfChar; Index++) {\r
- Count[BitLen[Index]]++;\r
+ //\r
+ // Count array index should not be greater than or equal to its size.\r
+ //\r
+ if (BitLen[Index] < (sizeof (Count)/sizeof (UINT16))) {\r
+ Count[BitLen[Index]]++;\r
+ } else {\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
}\r
\r
+ Start[0] = 0;\r
Start[1] = 0;\r
\r
for (Index = 1; Index <= 16; Index++) {\r
for (Char = 0; Char < NumOfChar; Char++) {\r
\r
Len = BitLen[Char];\r
- if (Len == 0) {\r
+ if (Len == 0 || Len >= 17) {\r
continue;\r
}\r
\r
Index = (UINT16) (Len - TableBits);\r
\r
while (Index != 0) {\r
- if (*Pointer == 0) {\r
+ //\r
+ // Avail should be lesser than size of mRight and mLeft to prevent buffer overflow.\r
+ //\r
+ if ((*Pointer == 0) && (Avail < sizeof (Sd->mRight)/sizeof (UINT16)) && (Avail < sizeof (Sd->mLeft)/sizeof (UINT16))) {\r
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
*Pointer = Avail++;\r
}\r
\r
- if (Index3 & Mask) {\r
+ //\r
+ // *Pointer should be lesser than size of mRight and mLeft to prevent buffer overflow.\r
+ //\r
+ if ((Index3 & Mask) && (*Pointer < (sizeof (Sd->mRight)/sizeof (UINT16)))) {\r
Pointer = &Sd->mRight[*Pointer];\r
- } else {\r
+ } else if (*Pointer < (sizeof (Sd->mLeft)/sizeof (UINT16))) {\r
Pointer = &Sd->mLeft[*Pointer];\r
}\r
\r
\r
Number = (UINT16) GetBits (Sd, nbit);\r
\r
+ if ((Number > sizeof (Sd->mPTLen)) || (nn > sizeof (Sd->mPTLen))) {\r
+ //\r
+ // Fail if Number or nn is greater than size of mPTLen\r
+ //\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
+\r
if (Number == 0) {\r
CharC = (UINT16) GetBits (Sd, nbit);\r
\r
if (Index == Special) {\r
CharC = (UINT16) GetBits (Sd, 2);\r
while ((INT16) (--CharC) >= 0) {\r
+ if (Index >= sizeof (Sd->mPTLen)) {\r
+ //\r
+ // Fail if Index is greater than or equal to mPTLen\r
+ //\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
Sd->mPTLen[Index++] = 0;\r
}\r
}\r
/*++\r
\r
-Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2010, 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
// the optional header to verify a desired directory entry is there.\r
//\r
\r
- if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
+ if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC && RelocDir->Size > 0) {\r
RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress);\r
RelocBaseEnd = PeCoffLoaderImageAddress (\r
ImageContext,\r
RelocDir->VirtualAddress + RelocDir->Size - 1\r
);\r
+ if ((RelocBase == NULL) || (RelocBaseEnd == NULL)) {\r
+ //\r
+ // If the base start or end address resolved to 0, then fail.\r
+ //\r
+ return EFI_LOAD_ERROR;\r
+ }\r
} else {\r
//\r
// Set base and end to bypass processing below.\r
// Find the relocation block\r
//\r
RelocDir = &Hdr.Te->DataDirectory[0];\r
- RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
- ImageContext->ImageAddress + \r
- RelocDir->VirtualAddress +\r
- sizeof(EFI_TE_IMAGE_HEADER) - \r
- Hdr.Te->StrippedSize\r
- );\r
- RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
+ if (RelocDir->Size > 0) {\r
+ RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
+ ImageContext->ImageAddress +\r
+ RelocDir->VirtualAddress +\r
+ sizeof(EFI_TE_IMAGE_HEADER) -\r
+ Hdr.Te->StrippedSize\r
+ );\r
+ RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
+ } else {\r
+ //\r
+ // Set base and end to bypass processing below.\r
+ //\r
+ RelocBase = NULL;\r
+ RelocBaseEnd = NULL;\r
+ }\r
}\r
\r
//\r
RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);\r
if (!(ImageContext->IsTeImage)) {\r
FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);\r
+\r
+ if (FixupBase == NULL) {\r
+ //\r
+ // If the FixupBase address resolved to 0, then fail.\r
+ //\r
+ return EFI_LOAD_ERROR;\r
+ }\r
} else {\r
FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
RelocBase->VirtualAddress +\r
/*++\r
\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
- // Put break point in module that contained the error.\r
+ // Put dead loop in module that contained the error.\r
//\r
- EFI_BREAKPOINT ();\r
+ EFI_DEADLOOP ();\r
}\r
\r
VOID\r
/*++\r
\r
-Copyright (c) 2004 - 2005, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
\r
ReturnReg = EfiCallEsalService (&Guid, IoRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
+ ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);\r
\r
return ReturnReg.Status;\r
\r
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
\r
ReturnReg = EfiCallEsalService (&Guid, MemRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
+ ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);\r
\r
return ReturnReg.Status;\r
\r
/*++\r
\r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
&mPpiListStatusCode\r
);\r
if (EFI_ERROR (Status)) {\r
- EFI_BREAKPOINT ();\r
- return ;\r
+ EFI_DEADLOOP ();\r
}\r
//\r
// Publish a GUIDed HOB that contains a pointer to the status code PPI\r
sizeof (VOID *)\r
);\r
if (EFI_ERROR (Status)) {\r
- EFI_BREAKPOINT ();\r
- return ;\r
+ EFI_DEADLOOP ();\r
}\r
}\r
}\r
/*++\r
\r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
UINTN Current;\r
\r
- ASSERT (Table);\r
- ASSERT (Token);\r
+ ASSERT (Table != NULL);\r
+ ASSERT (Token != NULL);\r
\r
Current = 0;\r
*Token = 0;\r
/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
// Locate the HOB that contains the PPI structure for the memory journal\r
// We don't check for more than one.\r
//\r
+ StatusCodeMemoryPpi = NULL;\r
EfiLibGetSystemConfigurationTable (\r
&gEfiHobListGuid,\r
&HobList\r
(VOID **) &StatusCodeMemoryPpi,\r
NULL\r
);\r
- if (EFI_ERROR (Status)) {\r
+ if (EFI_ERROR (Status) || (StatusCodeMemoryPpi == NULL)) {\r
return ;\r
}\r
//\r
/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
// is connected.\r
//\r
mPeiReportStatusCode = NULL;\r
-\r
+ Pointer = NULL;\r
Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);\r
if (!EFI_ERROR (Status)) {\r
Status = GetNextGuidHob (&HobList, &gEfiStatusCodeRuntimeProtocolGuid, &Pointer, NULL);\r
- if (!EFI_ERROR (Status)) {\r
+ if (!EFI_ERROR (Status) && (Pointer != NULL)) {\r
mPeiReportStatusCode = (EFI_REPORT_STATUS_CODE) (*(UINTN *) Pointer);\r
}\r
}\r