Add more check to make sure code run safely.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10574 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4 2010-06-11 07:47:06 +00:00
parent 61ece967cb
commit 4ac4deb706
25 changed files with 275 additions and 102 deletions

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -75,7 +75,7 @@ Returns:
);
//
// Put break point in module that contained the error.
// Put dead loop in module that contained the error.
//
EFI_DEADLOOP ();
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -825,6 +825,11 @@ Returns:
return EFI_OUT_OF_RESOURCES;
}
//
// Initialize 'LogHob' to NULL before usage.
//
LogHob = NULL;
if (Ticker != 0) {
TimerValue = Ticker;
} else {
@ -837,7 +842,10 @@ Returns:
EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);
do {
Status = GetNextGuidHob (&HobList, &gEfiPeiPerformanceHobGuid, (VOID **) &LogHob, NULL);
if (EFI_ERROR (Status)) {
if (EFI_ERROR (Status) || (LogHob == NULL)) {
//
// Failed to get HOB for ProtocolGuid.
//
break;
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -436,11 +436,13 @@ Returns:
if (GraphicsOutput != NULL) {
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
} else {
} else if (UgaDraw != NULL) {
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
} else {
return EFI_UNSUPPORTED;
}
Instance = 0;

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -158,8 +158,7 @@ Arguments:
Returns:
EFI_SUCCESS - success
EFI_OUT_OF_RESOURCES - out of resources
Length of string printed to the console
--*/
{
@ -191,7 +190,7 @@ Returns:
//
Buffer = EfiLibAllocateZeroPool (0x10000);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
return 0;
}
if (GraphicsOutput != NULL) {
@ -371,10 +370,15 @@ Error:
EfiLibSafeFreePool (Blt);
EfiLibSafeFreePool (FontInfo);
#else
gBS->FreePool (LineBuffer);
EfiLibSafeFreePool (LineBuffer);
#endif
gBS->FreePool (Buffer);
return Status;
if (EFI_ERROR (Status)) {
return 0;
}
return BufferLen;
}
@ -440,19 +444,20 @@ Returns:
(VOID**)&UgaDraw
);
if (EFI_ERROR (Status)) {
return Status;
if (EFI_ERROR (Status) || (UgaDraw == NULL)) {
return 0;
}
}
Sto = NULL;
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleTextOutProtocolGuid,
(VOID**)&Sto
);
if (EFI_ERROR (Status)) {
return Status;
if (EFI_ERROR (Status) || (Sto == NULL)) {
return 0;
}
return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -123,8 +123,8 @@ Returns:
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
@ -132,7 +132,7 @@ Returns:
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -435,11 +435,13 @@ Returns:
if (GraphicsOutput != NULL) {
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
} else {
} else if (UgaDraw != NULL) {
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
} else {
return EFI_UNSUPPORTED;
}
Instance = 0;

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -125,8 +125,7 @@ Arguments:
Returns:
EFI_SUCCESS - success
EFI_OUT_OF_RESOURCES - out of resources
Length of string printed to the console
--*/
{
@ -158,7 +157,7 @@ Returns:
//
Buffer = EfiLibAllocateZeroPool (0x10000);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
return 0;
}
if (GraphicsOutput != NULL) {
@ -337,10 +336,15 @@ Error:
EfiLibSafeFreePool (Blt);
EfiLibSafeFreePool (FontInfo);
#else
gBS->FreePool (LineBuffer);
EfiLibSafeFreePool (LineBuffer);
#endif
gBS->FreePool (Buffer);
return Status;
if (EFI_ERROR (Status)) {
return 0;
}
return BufferLen;
}
@ -406,19 +410,20 @@ Returns:
(VOID **) &UgaDraw
);
if (EFI_ERROR (Status)) {
return Status;
if (EFI_ERROR (Status) || (UgaDraw != NULL)) {
return 0;
}
}
Sto = NULL;
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleTextOutProtocolGuid,
(VOID **) &Sto
);
if (EFI_ERROR (Status)) {
return Status;
if (EFI_ERROR (Status) || (Sto != NULL)) {
return 0;
}
return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -123,8 +123,8 @@ Returns:
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
@ -132,7 +132,7 @@ Returns:
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -466,6 +466,10 @@ Returns:
EFI_STATUS Status;
VOID *HobStart2;
//
// Initialize 'Buffer' to NULL before usage
//
Buffer = NULL;
HobStart2 = HobStart;
Status = GetNextGuidHob (
&HobStart2,
@ -473,9 +477,14 @@ Returns:
&Buffer,
&BufferSize
);
if (EFI_ERROR (Status) || (Buffer == NULL)) {
//
// Failed to get HOB for gPalEntryHob
//
return EFI_NOT_FOUND;
}
*PalEntry = *((EFI_PHYSICAL_ADDRESS *) Buffer);
return Status;
return EFI_SUCCESS;
}
@ -508,6 +517,10 @@ Returns:
EFI_STATUS Status;
VOID *HobStart2;
//
// Initialize 'Buffer' to NULL before usage
//
Buffer = NULL;
HobStart2 = HobStart;
Status = GetNextGuidHob (
&HobStart2,
@ -515,7 +528,13 @@ Returns:
&Buffer,
&BufferSize
);
if (EFI_ERROR (Status) || (Buffer == NULL)) {
//
// Failed to get HOB for gEfiIoBaseHobGuid
//
return EFI_NOT_FOUND;
}
*IoPortSpaceAddress = *((EFI_PHYSICAL_ADDRESS *) Buffer);
return Status;
return EFI_SUCCESS;
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -123,8 +123,8 @@ Returns:
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
@ -132,7 +132,7 @@ Returns:
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -123,8 +123,8 @@ Returns:
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
@ -132,7 +132,7 @@ Returns:
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -554,7 +554,11 @@ Returns:
Status = HiiDatabase->ExportPackageLists (HiiDatabase, Handle, &BufferSize, HiiPackageList);
}
if (HiiPackageList == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (EFI_ERROR (Status)) {
gBS->FreePool (HiiPackageList);
return Status;
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -551,6 +551,9 @@ IfrLibNewString (
LocateHiiProtocols ();
Languages = GetSupportedLanguages (PackageList);
if (Languages == NULL) {
return EFI_NOT_FOUND;
}
LangStrings = Languages;
while (*LangStrings != 0) {
@ -677,6 +680,9 @@ IfrLibSetString (
LocateHiiProtocols ();
Languages = GetSupportedLanguages (PackageList);
if (Languages == NULL) {
return EFI_NOT_FOUND;
}
LangStrings = Languages;
while (*LangStrings != 0) {

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -581,12 +581,18 @@ GluePeCoffLoaderRelocateImage (
// the optional header to verify a desired directory entry is there.
//
if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC && RelocDir->Size > 0) {
RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress);
RelocBaseEnd = PeCoffLoaderImageAddress (
ImageContext,
RelocDir->VirtualAddress + RelocDir->Size - 1
);
if ((RelocBase == NULL) || (RelocBaseEnd == NULL)) {
//
// If the base start or end address resolved to 0, then fail.
//
return RETURN_LOAD_ERROR;
}
} else {
//
// Set base and end to bypass processing below.
@ -602,6 +608,7 @@ GluePeCoffLoaderRelocateImage (
// Find the relocation block
//
RelocDir = &Hdr.Te->DataDirectory[0];
if (RelocDir->Size > 0) {
RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(
ImageContext->ImageAddress +
RelocDir->VirtualAddress +
@ -609,6 +616,13 @@ GluePeCoffLoaderRelocateImage (
Hdr.Te->StrippedSize
);
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);
} else {
//
// Set base and end to bypass processing below.
//
RelocBase = NULL;
RelocBaseEnd = NULL;
}
}
//
@ -621,6 +635,13 @@ GluePeCoffLoaderRelocateImage (
RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);
if (!(ImageContext->IsTeImage)) {
FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);
if (FixupBase == NULL) {
//
// If the FixupBase address resolved to 0, then fail.
//
return RETURN_LOAD_ERROR;
}
} else {
FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +
RelocBase->VirtualAddress +

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -152,15 +152,32 @@ GlueMakeTable (
UINT16 WordOfStart;
UINT16 WordOfCount;
//
// TableBits should not be greater than 16.
//
if (TableBits >= (sizeof (Count)/sizeof (UINT16))) {
return (UINT16) BAD_TABLE;
}
for (Index = 1; Index <= 16; Index++) {
//
// Initialize Count array starting from Index 0, as there is a possibility of Count array being uninitialized.
//
for (Index = 0; Index <= 16; Index++) {
Count[Index] = 0;
}
for (Index = 0; Index < NumOfChar; Index++) {
//
// Count array index should not be greater than or equal to its size.
//
if (BitLen[Index] < (sizeof (Count)/sizeof (UINT16))) {
Count[BitLen[Index]]++;
} else {
return (UINT16) BAD_TABLE;
}
}
Start[0] = 0;
Start[1] = 0;
for (Index = 1; Index <= 16; Index++) {
@ -201,7 +218,7 @@ GlueMakeTable (
for (Char = 0; Char < NumOfChar; Char++) {
Len = BitLen[Char];
if (Len == 0) {
if (Len == 0 || Len >= 17) {
continue;
}
@ -220,14 +237,20 @@ GlueMakeTable (
Index = (UINT16) (Len - TableBits);
while (Index != 0) {
if (*Pointer == 0) {
//
// Avail should be lesser than size of mRight and mLeft to prevent buffer overflow.
//
if ((*Pointer == 0) && (Avail < sizeof (Sd->mRight)/sizeof (UINT16)) && (Avail < sizeof (Sd->mLeft)/sizeof (UINT16))) {
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
*Pointer = Avail++;
}
if (Index3 & Mask) {
//
// *Pointer should be lesser than size of mRight and mLeft to prevent buffer overflow.
//
if ((Index3 & Mask) && (*Pointer < (sizeof (Sd->mRight)/sizeof (UINT16)))) {
Pointer = &Sd->mRight[*Pointer];
} else {
} else if (*Pointer < (sizeof (Sd->mLeft)/sizeof (UINT16))) {
Pointer = &Sd->mLeft[*Pointer];
}
@ -328,6 +351,13 @@ GlueReadPTLen (
//
Number = (UINT16) GetBits (Sd, nbit);
if ((Number > sizeof (Sd->mPTLen)) || (nn > sizeof (Sd->mPTLen))) {
//
// Fail if Number or nn is greater than size of mPTLen
//
return (UINT16) BAD_TABLE;
}
if (Number == 0) {
//
// This represents only Huffman code used
@ -377,6 +407,12 @@ GlueReadPTLen (
if (Index == Special) {
CharC = (UINT16) GetBits (Sd, 2);
while ((INT16) (--CharC) >= 0) {
if (Index >= sizeof (Sd->mPTLen)) {
//
// Fail if Index is greater than or equal to mPTLen
//
return (UINT16) BAD_TABLE;
}
Sd->mPTLen[Index++] = 0;
}
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -483,6 +483,9 @@ Returns:
do {
GuidHob = (EFI_HOB_GUID_TYPE *)GlueGetNextGuidHob (&gEfiPeiPerformanceHobGuid, &HobList);
if (GuidHob == NULL) {
break;
}
LogHob = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)GET_GUID_HOB_DATA (GuidHob);
for (Index = 0; Index < LogHob->NumberOfEntries; Index++) {

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -52,6 +52,9 @@ GluePreparePackages (
HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));
ASSERT (HiiPackages != NULL);
if (HiiPackages == NULL) {
return NULL;
}
HiiPackages->GuidId = (EFI_GUID *) Guid;
HiiPackages->NumberOfPackages = NumberOfPackages;

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -312,14 +312,32 @@ Returns:
UINT16 NextCode;
UINT16 Mask;
for (Index = 1; Index <= 16; Index++) {
//
// TableBits should not be greater than 16.
//
if (TableBits >= (sizeof (Count)/sizeof (UINT16))) {
return (UINT16) BAD_TABLE;
}
//
// Initialize Count array starting from Index 0, as there is a possibility of Count array being uninitialized.
//
for (Index = 0; Index <= 16; Index++) {
Count[Index] = 0;
}
for (Index = 0; Index < NumOfChar; Index++) {
//
// Count array index should not be greater than or equal to its size.
//
if (BitLen[Index] < (sizeof (Count)/sizeof (UINT16))) {
Count[BitLen[Index]]++;
} else {
return (UINT16) BAD_TABLE;
}
}
Start[0] = 0;
Start[1] = 0;
for (Index = 1; Index <= 16; Index++) {
@ -358,7 +376,7 @@ Returns:
for (Char = 0; Char < NumOfChar; Char++) {
Len = BitLen[Char];
if (Len == 0) {
if (Len == 0 || Len >= 17) {
continue;
}
@ -377,14 +395,20 @@ Returns:
Index = (UINT16) (Len - TableBits);
while (Index != 0) {
if (*Pointer == 0) {
//
// Avail should be lesser than size of mRight and mLeft to prevent buffer overflow.
//
if ((*Pointer == 0) && (Avail < sizeof (Sd->mRight)/sizeof (UINT16)) && (Avail < sizeof (Sd->mLeft)/sizeof (UINT16))) {
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
*Pointer = Avail++;
}
if (Index3 & Mask) {
//
// *Pointer should be lesser than size of mRight and mLeft to prevent buffer overflow.
//
if ((Index3 & Mask) && (*Pointer < (sizeof (Sd->mRight)/sizeof (UINT16)))) {
Pointer = &Sd->mRight[*Pointer];
} else {
} else if (*Pointer < (sizeof (Sd->mLeft)/sizeof (UINT16))) {
Pointer = &Sd->mLeft[*Pointer];
}
@ -493,6 +517,13 @@ Returns:
Number = (UINT16) GetBits (Sd, nbit);
if ((Number > sizeof (Sd->mPTLen)) || (nn > sizeof (Sd->mPTLen))) {
//
// Fail if Number or nn is greater than size of mPTLen
//
return (UINT16) BAD_TABLE;
}
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, nbit);
@ -528,6 +559,12 @@ Returns:
if (Index == Special) {
CharC = (UINT16) GetBits (Sd, 2);
while ((INT16) (--CharC) >= 0) {
if (Index >= sizeof (Sd->mPTLen)) {
//
// Fail if Index is greater than or equal to mPTLen
//
return (UINT16) BAD_TABLE;
}
Sd->mPTLen[Index++] = 0;
}
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -785,12 +785,18 @@ Returns:
// the optional header to verify a desired directory entry is there.
//
if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC && RelocDir->Size > 0) {
RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress);
RelocBaseEnd = PeCoffLoaderImageAddress (
ImageContext,
RelocDir->VirtualAddress + RelocDir->Size - 1
);
if ((RelocBase == NULL) || (RelocBaseEnd == NULL)) {
//
// If the base start or end address resolved to 0, then fail.
//
return EFI_LOAD_ERROR;
}
} else {
//
// Set base and end to bypass processing below.
@ -806,6 +812,7 @@ Returns:
// Find the relocation block
//
RelocDir = &Hdr.Te->DataDirectory[0];
if (RelocDir->Size > 0) {
RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(
ImageContext->ImageAddress +
RelocDir->VirtualAddress +
@ -813,6 +820,13 @@ Returns:
Hdr.Te->StrippedSize
);
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);
} else {
//
// Set base and end to bypass processing below.
//
RelocBase = NULL;
RelocBaseEnd = NULL;
}
}
//
@ -825,6 +839,13 @@ Returns:
RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);
if (!(ImageContext->IsTeImage)) {
FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);
if (FixupBase == NULL) {
//
// If the FixupBase address resolved to 0, then fail.
//
return EFI_LOAD_ERROR;
}
} else {
FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +
RelocBase->VirtualAddress +

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -66,9 +66,9 @@ Returns:
);
//
// Put break point in module that contained the error.
// Put dead loop in module that contained the error.
//
EFI_BREAKPOINT ();
EFI_DEADLOOP ();
}
VOID

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -947,6 +947,7 @@ Returns:
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, IoRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);
ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);
return ReturnReg.Status;
@ -1015,6 +1016,7 @@ Returns:
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, MemRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);
ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);
return ReturnReg.Status;

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -289,8 +289,7 @@ Returns:
&mPpiListStatusCode
);
if (EFI_ERROR (Status)) {
EFI_BREAKPOINT ();
return ;
EFI_DEADLOOP ();
}
//
// Publish a GUIDed HOB that contains a pointer to the status code PPI
@ -306,8 +305,7 @@ Returns:
sizeof (VOID *)
);
if (EFI_ERROR (Status)) {
EFI_BREAKPOINT ();
return ;
EFI_DEADLOOP ();
}
}
}

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -2073,8 +2073,8 @@ Returns:
{
UINTN Current;
ASSERT (Table);
ASSERT (Token);
ASSERT (Table != NULL);
ASSERT (Token != NULL);
Current = 0;
*Token = 0;

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -124,6 +124,7 @@ Returns:
// Locate the HOB that contains the PPI structure for the memory journal
// We don't check for more than one.
//
StatusCodeMemoryPpi = NULL;
EfiLibGetSystemConfigurationTable (
&gEfiHobListGuid,
&HobList
@ -134,7 +135,7 @@ Returns:
(VOID **) &StatusCodeMemoryPpi,
NULL
);
if (EFI_ERROR (Status)) {
if (EFI_ERROR (Status) || (StatusCodeMemoryPpi == NULL)) {
return ;
}
//

View File

@ -1,6 +1,6 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -133,11 +133,11 @@ Returns:
// is connected.
//
mPeiReportStatusCode = NULL;
Pointer = NULL;
Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);
if (!EFI_ERROR (Status)) {
Status = GetNextGuidHob (&HobList, &gEfiStatusCodeRuntimeProtocolGuid, &Pointer, NULL);
if (!EFI_ERROR (Status)) {
if (!EFI_ERROR (Status) && (Pointer != NULL)) {
mPeiReportStatusCode = (EFI_REPORT_STATUS_CODE) (*(UINTN *) Pointer);
}
}