Add more check to avoid code enter into wrong state.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10068 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4 2010-02-25 10:08:54 +00:00
parent bade9bf5b2
commit 234980f6e9
7 changed files with 46 additions and 14 deletions

View File

@ -243,7 +243,7 @@ InitializeHiiDatabase (
@param This A pointer to the EFI_HII_PROTOCOL instance. @param This A pointer to the EFI_HII_PROTOCOL instance.
@param HandleBufferLength On input, a pointer to the length of the handle buffer. @param HandleBufferLength On input, a pointer to the length of the handle buffer.
On output, the length of the handle buffer that is required for the handles found. On output, the length of the handle buffer that is required for the handles found.
@param Handle An array of EFI_HII_HANDLE instances returned. @param Handle Pointer to an array of EFI_HII_HANDLE instances returned.
Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack() in the Packages section. Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack() in the Packages section.
@retval EFI_SUCCESS Handle was updated successfully. @retval EFI_SUCCESS Handle was updated successfully.
@ -257,13 +257,13 @@ EFIAPI
HiiFindHandles ( HiiFindHandles (
IN EFI_HII_PROTOCOL *This, IN EFI_HII_PROTOCOL *This,
IN OUT UINT16 *HandleBufferLength, IN OUT UINT16 *HandleBufferLength,
OUT FRAMEWORK_EFI_HII_HANDLE Handle[1] OUT FRAMEWORK_EFI_HII_HANDLE *Handle
) )
{ {
UINT16 Count; UINT16 Count;
LIST_ENTRY *Link; LIST_ENTRY *Link;
HII_THUNK_CONTEXT *ThunkContext; HII_THUNK_CONTEXT *ThunkContext;
HII_THUNK_PRIVATE_DATA *Private; HII_THUNK_PRIVATE_DATA *Private;
if (HandleBufferLength == NULL) { if (HandleBufferLength == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;

View File

@ -401,8 +401,12 @@ FindStringPackAndUpdatePackListWithOnlyIfrPack (
if (ThunkContext != IfrThunkContext) { if (ThunkContext != IfrThunkContext) {
if (CompareGuid (&IfrThunkContext->TagGuid, &ThunkContext->TagGuid) && (ThunkContext->IfrPackageCount == 0)) { if (CompareGuid (&IfrThunkContext->TagGuid, &ThunkContext->TagGuid) && (ThunkContext->IfrPackageCount == 0)) {
StringPackageListHeader = NULL;
Status = ExportPackageLists (ThunkContext->UefiHiiHandle, &StringPackageListHeader, &Size); Status = ExportPackageLists (ThunkContext->UefiHiiHandle, &StringPackageListHeader, &Size);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
if (StringPackageListHeader == NULL) {
return EFI_NOT_FOUND;
}
IfrThunkContext->StringPackageCount = GetPackageCountByType (StringPackageListHeader, EFI_HII_PACKAGE_STRINGS); IfrThunkContext->StringPackageCount = GetPackageCountByType (StringPackageListHeader, EFI_HII_PACKAGE_STRINGS);
// //
@ -506,6 +510,10 @@ UefiRegisterPackageList (
ASSERT ((StringPackageCount >=1 && IfrPackageCount == 1) || (FontPackageCount > 0)); ASSERT ((StringPackageCount >=1 && IfrPackageCount == 1) || (FontPackageCount > 0));
if (IfrPackageCount > 0) { if (IfrPackageCount > 0) {
IfrPackage = GetIfrPackage (Packages); IfrPackage = GetIfrPackage (Packages);
if (IfrPackage == NULL) {
Status = EFI_NOT_FOUND;
goto Done;
}
GetFormSetGuid (IfrPackage, &ThunkContext->TagGuid); GetFormSetGuid (IfrPackage, &ThunkContext->TagGuid);
} else { } else {
ASSERT (FontPackageCount > 0); ASSERT (FontPackageCount > 0);
@ -860,8 +868,12 @@ RemovePackNotify (
// //
if (ThunkContext != NULL) { if (ThunkContext != NULL) {
if (!ThunkContext->ByFrameworkHiiNewPack) { if (!ThunkContext->ByFrameworkHiiNewPack) {
HiiPackageList = NULL;
Status = ExportPackageLists (Handle, &HiiPackageList, &BufferSize); Status = ExportPackageLists (Handle, &HiiPackageList, &BufferSize);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
if (HiiPackageList == NULL) {
return EFI_NOT_FOUND;
}
if (GetPackageCountByType (HiiPackageList, EFI_HII_PACKAGE_STRINGS) == 1) { if (GetPackageCountByType (HiiPackageList, EFI_HII_PACKAGE_STRINGS) == 1) {
// //

View File

@ -102,7 +102,7 @@ PlatformBdsShowProgress (
(VOID **) &UgaDraw (VOID **) &UgaDraw
); );
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status) || (GraphicsOutput == NULL && UgaDraw == NULL)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }

View File

@ -556,7 +556,7 @@ ParseOpCodes (
// //
// If scope bit set, push onto scope stack // If scope bit set, push onto scope stack
// //
if (Scope) { if (Scope != 0) {
PushScope (Operand); PushScope (Operand);
} }
@ -717,15 +717,17 @@ ParseOpCodes (
// //
case EFI_IFR_SUBTITLE_OP: case EFI_IFR_SUBTITLE_OP:
CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CurrentStatement->Flags = ((EFI_IFR_SUBTITLE *) OpCodeData)->Flags; CurrentStatement->Flags = ((EFI_IFR_SUBTITLE *) OpCodeData)->Flags;
if (Scope) { if (Scope != 0) {
mInScopeSubtitle = TRUE; mInScopeSubtitle = TRUE;
} }
break; break;
case EFI_IFR_TEXT_OP: case EFI_IFR_TEXT_OP:
CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CopyMem (&CurrentStatement->TextTwo, &((EFI_IFR_TEXT *) OpCodeData)->TextTwo, sizeof (EFI_STRING_ID)); CopyMem (&CurrentStatement->TextTwo, &((EFI_IFR_TEXT *) OpCodeData)->TextTwo, sizeof (EFI_STRING_ID));
break; break;
@ -735,6 +737,7 @@ ParseOpCodes (
// //
case EFI_IFR_ACTION_OP: case EFI_IFR_ACTION_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
if (OpCodeLength == sizeof (EFI_IFR_ACTION_1)) { if (OpCodeLength == sizeof (EFI_IFR_ACTION_1)) {
// //
@ -748,11 +751,13 @@ ParseOpCodes (
case EFI_IFR_RESET_BUTTON_OP: case EFI_IFR_RESET_BUTTON_OP:
CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CopyMem (&CurrentStatement->DefaultId, &((EFI_IFR_RESET_BUTTON *) OpCodeData)->DefaultId, sizeof (EFI_DEFAULT_ID)); CopyMem (&CurrentStatement->DefaultId, &((EFI_IFR_RESET_BUTTON *) OpCodeData)->DefaultId, sizeof (EFI_DEFAULT_ID));
break; break;
case EFI_IFR_REF_OP: case EFI_IFR_REF_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CopyMem (&CurrentStatement->RefFormId, &((EFI_IFR_REF *) OpCodeData)->FormId, sizeof (EFI_FORM_ID)); CopyMem (&CurrentStatement->RefFormId, &((EFI_IFR_REF *) OpCodeData)->FormId, sizeof (EFI_FORM_ID));
if (OpCodeLength >= sizeof (EFI_IFR_REF2)) { if (OpCodeLength >= sizeof (EFI_IFR_REF2)) {
@ -771,6 +776,7 @@ ParseOpCodes (
case EFI_IFR_ONE_OF_OP: case EFI_IFR_ONE_OF_OP:
case EFI_IFR_NUMERIC_OP: case EFI_IFR_NUMERIC_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CurrentStatement->Flags = ((EFI_IFR_ONE_OF *) OpCodeData)->Flags; CurrentStatement->Flags = ((EFI_IFR_ONE_OF *) OpCodeData)->Flags;
Value = &CurrentStatement->HiiValue; Value = &CurrentStatement->HiiValue;
@ -820,6 +826,7 @@ ParseOpCodes (
case EFI_IFR_ORDERED_LIST_OP: case EFI_IFR_ORDERED_LIST_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CurrentStatement->Flags = ((EFI_IFR_ORDERED_LIST *) OpCodeData)->Flags; CurrentStatement->Flags = ((EFI_IFR_ORDERED_LIST *) OpCodeData)->Flags;
CurrentStatement->MaxContainers = ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers; CurrentStatement->MaxContainers = ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers;
@ -837,6 +844,7 @@ ParseOpCodes (
case EFI_IFR_CHECKBOX_OP: case EFI_IFR_CHECKBOX_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CurrentStatement->Flags = ((EFI_IFR_CHECKBOX *) OpCodeData)->Flags; CurrentStatement->Flags = ((EFI_IFR_CHECKBOX *) OpCodeData)->Flags;
CurrentStatement->StorageWidth = sizeof (BOOLEAN); CurrentStatement->StorageWidth = sizeof (BOOLEAN);
@ -846,6 +854,7 @@ ParseOpCodes (
case EFI_IFR_STRING_OP: case EFI_IFR_STRING_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
// //
// MinSize is the minimum number of characters that can be accepted for this opcode, // MinSize is the minimum number of characters that can be accepted for this opcode,
@ -864,6 +873,7 @@ ParseOpCodes (
case EFI_IFR_PASSWORD_OP: case EFI_IFR_PASSWORD_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
// //
// MinSize is the minimum number of characters that can be accepted for this opcode, // MinSize is the minimum number of characters that can be accepted for this opcode,
@ -881,6 +891,7 @@ ParseOpCodes (
case EFI_IFR_DATE_OP: case EFI_IFR_DATE_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CurrentStatement->Flags = ((EFI_IFR_DATE *) OpCodeData)->Flags; CurrentStatement->Flags = ((EFI_IFR_DATE *) OpCodeData)->Flags;
CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_DATE; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_DATE;
@ -889,6 +900,7 @@ ParseOpCodes (
case EFI_IFR_TIME_OP: case EFI_IFR_TIME_OP:
CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm);
ASSERT (CurrentStatement != NULL);
CurrentStatement->Flags = ((EFI_IFR_TIME *) OpCodeData)->Flags; CurrentStatement->Flags = ((EFI_IFR_TIME *) OpCodeData)->Flags;
CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_TIME; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_TIME;
@ -999,10 +1011,17 @@ ParseOpCodes (
break; break;
default: default:
//
// Make sure CurrentStatement is not NULL.
// If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
// file is wrongly generated by tools such as VFR Compiler.
//
ASSERT (CurrentStatement != NULL);
ImageId = &CurrentStatement->ImageId; ImageId = &CurrentStatement->ImageId;
break; break;
} }
ASSERT (ImageId != NULL);
CopyMem (ImageId, &((EFI_IFR_IMAGE *) OpCodeData)->Id, sizeof (EFI_IMAGE_ID)); CopyMem (ImageId, &((EFI_IFR_IMAGE *) OpCodeData)->Id, sizeof (EFI_IMAGE_ID));
break; break;
@ -1010,6 +1029,7 @@ ParseOpCodes (
// Refresh // Refresh
// //
case EFI_IFR_REFRESH_OP: case EFI_IFR_REFRESH_OP:
ASSERT (CurrentStatement != NULL);
CurrentStatement->RefreshInterval = ((EFI_IFR_REFRESH *) OpCodeData)->RefreshInterval; CurrentStatement->RefreshInterval = ((EFI_IFR_REFRESH *) OpCodeData)->RefreshInterval;
break; break;

View File

@ -727,8 +727,8 @@ GetIfrBinaryData (
Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList); Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status) || HiiPackageList == NULL) {
return Status; return EFI_NOT_FOUND;
} }
// //

View File

@ -377,7 +377,7 @@ SmbiosFindHandle (
} }
} }
if (Link == &mStructureList) { if (Link == &mStructureList || StructureNode == NULL) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} else { } else {
*HandleNum = StructureNode->Structure->Handle; *HandleNum = StructureNode->Structure->Handle;

View File

@ -161,7 +161,7 @@ SmbiosProcessDataRecord (
} }
} }
if (Link == &mStructureList) { if (Link == &mStructureList || StructureNode == NULL) {
// //
// Not found, create a new structure // Not found, create a new structure