From cb263708057c72e1b83939f68cd5e8118ed35ed2 Mon Sep 17 00:00:00 2001 From: klu2 Date: Fri, 23 Jan 2009 03:32:01 +0000 Subject: Fix issue from code scrub. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7349 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 8 +++ .../Universal/BdsDxe/BootMaint/BootMaint.c | 11 ++++ .../Universal/BdsDxe/BootMaint/BootOption.c | 19 ++++-- .../Universal/BdsDxe/BootMaint/ConsoleOption.c | 68 +--------------------- .../Universal/BdsDxe/BootMaint/UpdatePage.c | 23 ++++++-- MdeModulePkg/Universal/BdsDxe/BootMaint/Variable.c | 4 ++ .../Universal/BdsDxe/BootMngr/BootManager.c | 1 + .../Universal/BdsDxe/DeviceMngr/DeviceManager.c | 2 +- MdeModulePkg/Universal/BdsDxe/Hotkey.c | 6 +- MdeModulePkg/Universal/BdsDxe/MemoryTest.c | 2 +- 10 files changed, 65 insertions(+), 79 deletions(-) (limited to 'MdeModulePkg/Universal') diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index c70559e098..d8bf26a7bb 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -138,6 +138,14 @@ BdsBootDeviceSelect ( // UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *mBootNext); BootOption = BdsLibVariableToOption (&BootLists, Buffer); + + // + // If fail to get boot option from variable, just return and do nothing. + // + if (BootOption == NULL) { + return; + } + BootOption->BootCurrent = *mBootNext; } // diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c index f93cfc48a0..1e3f01a0e9 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c @@ -580,6 +580,7 @@ ApplyChangeHandler ( break; case FORM_BOOT_DEL_ID: + ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->BootOptionDel) / sizeof (UINT8))); for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; @@ -590,6 +591,7 @@ ApplyChangeHandler ( break; case FORM_DRV_DEL_ID: + ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->DriverOptionDel) / sizeof (UINT8))); for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; @@ -638,12 +640,16 @@ ApplyChangeHandler ( NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; NewTerminalContext->BaudRateIndex = CurrentFakeNVMap->COMBaudRate; + ASSERT (CurrentFakeNVMap->COMBaudRate < (sizeof (BaudRateList) / sizeof (BaudRateList[0]))); NewTerminalContext->BaudRate = BaudRateList[CurrentFakeNVMap->COMBaudRate].Value; NewTerminalContext->DataBitsIndex = CurrentFakeNVMap->COMDataRate; + ASSERT (CurrentFakeNVMap->COMDataRate < (sizeof (DataBitsList) / sizeof (DataBitsList[0]))); NewTerminalContext->DataBits = (UINT8) DataBitsList[CurrentFakeNVMap->COMDataRate].Value; NewTerminalContext->StopBitsIndex = CurrentFakeNVMap->COMStopBits; + ASSERT (CurrentFakeNVMap->COMStopBits < (sizeof (StopBitsList) / sizeof (StopBitsList[0]))); NewTerminalContext->StopBits = (UINT8) StopBitsList[CurrentFakeNVMap->COMStopBits].Value; NewTerminalContext->ParityIndex = CurrentFakeNVMap->COMParity; + ASSERT (CurrentFakeNVMap->COMParity < (sizeof (ParityList) / sizeof (ParityList[0]))); NewTerminalContext->Parity = (UINT8) ParityList[CurrentFakeNVMap->COMParity].Value; NewTerminalContext->TerminalType = CurrentFakeNVMap->COMTerminalType; @@ -658,6 +664,7 @@ ApplyChangeHandler ( break; case FORM_CON_IN_ID: + ASSERT ((ConsoleInpMenu.MenuNumber + TerminalMenu.MenuNumber) <= (sizeof (CurrentFakeNVMap->ConsoleCheck) / sizeof (UINT8))); for (Index = 0; Index < ConsoleInpMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&ConsoleInpMenu, Index); NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; @@ -674,6 +681,7 @@ ApplyChangeHandler ( break; case FORM_CON_OUT_ID: + ASSERT ((ConsoleOutMenu.MenuNumber + TerminalMenu.MenuNumber) <= (sizeof (CurrentFakeNVMap->ConsoleCheck) / sizeof (UINT8))); for (Index = 0; Index < ConsoleOutMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&ConsoleOutMenu, Index); NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; @@ -690,6 +698,7 @@ ApplyChangeHandler ( break; case FORM_CON_ERR_ID: + ASSERT ((ConsoleErrMenu.MenuNumber + TerminalMenu.MenuNumber) <= (sizeof (CurrentFakeNVMap->ConsoleCheck) / sizeof (UINT8))); for (Index = 0; Index < ConsoleErrMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&ConsoleErrMenu, Index); NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; @@ -752,12 +761,14 @@ DiscardChangeHandler ( break; case FORM_BOOT_DEL_ID: + ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->BootOptionDel) / sizeof (CurrentFakeNVMap->BootOptionDel[0]))); for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { CurrentFakeNVMap->BootOptionDel[Index] = 0x00; } break; case FORM_DRV_DEL_ID: + ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CurrentFakeNVMap->DriverOptionDel) / sizeof (CurrentFakeNVMap->DriverOptionDel[0]))); for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { CurrentFakeNVMap->DriverOptionDel[Index] = 0x00; } diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c index acfd548e5e..e9caf5958a 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c @@ -847,7 +847,8 @@ BOpt_FreeLegacyOptions ( @param CallbackData The BMM context data. - @return The number of the Var Boot####. + @return EFI_NOT_FOUND Fail to find "BootOrder" variable. + @return EFI_SUCESS Success build boot option menu. **/ EFI_STATUS @@ -892,7 +893,10 @@ BOpt_GetBootOptions ( &gEfiGlobalVariableGuid, &BootOrderListSize ); - + if (BootOrderList == NULL) { + return EFI_NOT_FOUND; + } + // // Get the BootNext from the Var // @@ -1067,7 +1071,7 @@ BOpt_GetBootOptions ( FreePool (BootOrderList); } BootOptionMenu.MenuNumber = MenuCount; - return MenuCount; + return EFI_SUCCESS; } /** @@ -1493,9 +1497,9 @@ BOpt_GetDriverOptionNumber ( @param CallbackData The BMM context data. - @return EFI_SUCESS The functin completes successfully. + @retval EFI_SUCESS The functin completes successfully. @retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation. - + @retval EFI_NOT_FOUND Fail to get "DriverOrder" variable. **/ EFI_STATUS @@ -1532,7 +1536,10 @@ BOpt_GetDriverOptions ( &gEfiGlobalVariableGuid, &DriverOrderListSize ); - + if (DriverOrderList == NULL) { + return EFI_NOT_FOUND; + } + for (Index = 0; Index < DriverOrderListSize / sizeof (UINT16); Index++) { UnicodeSPrint ( DriverString, diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c index 0fc187aca3..da0a8389fa 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c @@ -14,21 +14,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "BootMaint.h" -/** - Function creates a device path data structure that identically matches the - device path passed in. - - @param DevPath A pointer to a device path data structure. - - @return The new copy of DevPath is created to identically match the input. - @retval NULL Otherwise, NULL is returned. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -DevicePathInstanceDup ( - IN EFI_DEVICE_PATH_PROTOCOL *DevPath - ); - /** Update Com Ports attributes from DevicePath @@ -423,7 +408,7 @@ LocateSerialIo ( NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext; CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32)); - NewTerminalContext->DevicePath = DevicePathInstanceDup (DevicePath); + NewTerminalContext->DevicePath = DuplicateDevicePath (DevicePath); // // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system! // coz' the misc data for each platform is not correct, actually it's the device path stored in @@ -547,7 +532,6 @@ LocateSerialIo ( /** Update Com Ports attributes from DevicePath - @param DevicePath DevicePath that contains Com ports @retval EFI_SUCCESS The update is successful. @@ -665,54 +649,6 @@ UpdateComAttributeFromVariable ( return EFI_SUCCESS; } -/** - Function creates a device path data structure that identically matches the - device path passed in. - - - @param DevPath A pointer to a device path data structure. - - @return The new copy of DevPath is created to identically match the input. - @retval NULL Otherwise, NULL is returned. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -DevicePathInstanceDup ( - IN EFI_DEVICE_PATH_PROTOCOL *DevPath - ) -{ - EFI_DEVICE_PATH_PROTOCOL *NewDevPath; - EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; - EFI_DEVICE_PATH_PROTOCOL *Temp; - UINT8 *Ptr; - UINTN Size; - - // - // get the size of an instance from the input - // - Temp = DevPath; - DevicePathInst = GetNextDevicePathInstance (&Temp, &Size); - - // - // Make a copy and set proper end type - // - NewDevPath = NULL; - if (Size != 0) { - NewDevPath = AllocateZeroPool (Size); - ASSERT (NewDevPath != NULL); - } - - if (NewDevPath != NULL) { - CopyMem (NewDevPath, DevicePathInst, Size); - Ptr = (UINT8 *) NewDevPath; - Ptr += Size - sizeof (EFI_DEVICE_PATH_PROTOCOL); - Temp = (EFI_DEVICE_PATH_PROTOCOL *) Ptr; - SetDevicePathEndNode (Temp); - } - - return NewDevPath; -} - /** Build up Console Menu based on types passed in. The type can be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT @@ -818,7 +754,7 @@ GetConsoleMenu ( NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; NewMenuEntry->OptionNumber = Index2; - NewConsoleContext->DevicePath = DevicePathInstanceDup (DevicePathInst); + NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst); NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath); if (NULL == NewMenuEntry->DisplayString) { NewMenuEntry->DisplayString = DevicePathToStr (NewConsoleContext->DevicePath); diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c index 486f2fdcfc..9fa2556cd5 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c @@ -162,6 +162,7 @@ BootThisFile ( BDS_COMMON_OPTION *Option; Option = (BDS_COMMON_OPTION *) AllocatePool (sizeof (BDS_COMMON_OPTION)); + ASSERT (Option != NULL); Option->Description = FileContext->FileName; Option->DevicePath = FileContext->DevicePath; Option->LoadOptionsSize = 0; @@ -236,6 +237,7 @@ UpdateBootDelPage ( UpdatePageStart (CallbackData); CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu); + ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.BootOptionDel) / sizeof (CallbackData->BmmFakeNvData.BootOptionDel[0]))); for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; @@ -316,7 +318,8 @@ UpdateDrvDelPage ( UpdatePageStart (CallbackData); CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &DriverOptionMenu); - + + ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.DriverOptionDel) / sizeof (CallbackData->BmmFakeNvData.DriverOptionDel[0]))); for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index); @@ -434,6 +437,7 @@ UpdateConsolePage ( UpdatePageStart (CallbackData); + ASSERT (ConsoleMenu->MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.ConsoleCheck) / sizeof (CallbackData->BmmFakeNvData.ConsoleCheck[0]))); for (Index = 0; Index < ConsoleMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (ConsoleMenu, Index); NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext; @@ -518,10 +522,11 @@ UpdateOrderPage ( ZeroMem (CallbackData->BmmFakeNvData.OptionOrder, 100); IfrOptionList = AllocateZeroPool (sizeof (IFR_OPTION) * OptionMenu->MenuNumber); - if (NULL == IfrOptionList) { + if (IfrOptionList == NULL) { return ; } - + + ASSERT (OptionMenu->MenuNumber <= (sizeof (IfrOptionList) / sizeof (IfrOptionList[0]))); for (Index = 0; Index < OptionMenu->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index); IfrOptionList[Index].StringToken = NewMenuEntry->DisplayStringToken; @@ -736,12 +741,15 @@ UpdateConModePage ( if (EFI_ERROR (Status)) { continue; } + // // Build mode string Column x Row // UnicodeValueToString (ModeString, 0, Col, 0); + ASSERT ((StrLen (ModeString) + 1) < (sizeof (ModeString) / sizeof (ModeString[0]))); StrCat (ModeString, L" x "); UnicodeValueToString (RowString, 0, Row, 0); + ASSERT ((StrLen (ModeString) + StrLen(RowString)) < (sizeof (ModeString) / sizeof (ModeString[0]))); StrCat (ModeString, RowString); HiiLibNewString (CallbackData->BmmHiiHandle, &ModeToken[Index], ModeString); @@ -1023,7 +1031,11 @@ GetLegacyBootOptionVar ( &gEfiGlobalVariableGuid, &OrderSize ); - + + if (OrderBuffer == NULL) { + return NULL; + } + for (Index = 0; Index < OrderSize / sizeof (UINT16); Index++) { UnicodeSPrint (StrTemp, 100, L"Boot%04x", OrderBuffer[Index]); OptionBuffer = BdsLibGetVariableAndSize ( @@ -1177,6 +1189,9 @@ UpdateSetLegacyDeviceOrderPage ( OldData = CallbackData->BmmOldFakeNVData.LegacyBEV; break; + default: + DEBUG ((EFI_D_ERROR, "Invalid command ID for updating page!\n")); + return; } CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu); diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/Variable.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/Variable.c index 55af813d68..5cc7abcb5a 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMaint/Variable.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMaint/Variable.c @@ -437,6 +437,8 @@ Var_UpdateConsoleOption ( ) { Vendor.Header.Type = MESSAGING_DEVICE_PATH; Vendor.Header.SubType = MSG_VENDOR_DP; + + ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0]))); CopyMem ( &Vendor.Guid, &TerminalTypeGuid[NewTerminalContext->TerminalType], @@ -977,6 +979,7 @@ Var_UpdateBootOrder ( FreePool (BootOrderList); } + ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.OptionOrder) / sizeof (CallbackData->BmmFakeNvData.OptionOrder[0]))); for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { NewBootOrderList[Index] = (UINT16) (CallbackData->BmmFakeNvData.OptionOrder[Index] - 1); } @@ -1048,6 +1051,7 @@ Var_UpdateDriverOrder ( FreePool (DriverOrderList); } + ASSERT (DriverOrderListSize <= (sizeof (CallbackData->BmmFakeNvData.OptionOrder) / sizeof (CallbackData->BmmFakeNvData.OptionOrder[0]))); for (Index = 0; Index < DriverOrderListSize; Index++) { NewDriverOrderList[Index] = (UINT16) (CallbackData->BmmFakeNvData.OptionOrder[Index] - 1); } diff --git a/MdeModulePkg/Universal/BdsDxe/BootMngr/BootManager.c b/MdeModulePkg/Universal/BdsDxe/BootMngr/BootManager.c index d0ac2fc1dd..a1612cd1b1 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMngr/BootManager.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMngr/BootManager.c @@ -230,6 +230,7 @@ CallBootManager ( TempStr = DevicePathToStr (Option->DevicePath); TempSize = StrSize (TempStr); HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : ")); + ASSERT (HelpString != NULL); StrCat (HelpString, L"Device Path : "); StrCat (HelpString, TempStr); diff --git a/MdeModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/MdeModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c index f0e07ecc21..715e1013e7 100644 --- a/MdeModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c +++ b/MdeModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c @@ -234,7 +234,7 @@ CallDeviceManager ( // Get all the Hii handles // Status = HiiLibGetHiiHandles (&HandleBufferLength, &HiiHandles); - ASSERT_EFI_ERROR (Status); + ASSERT_EFI_ERROR (Status && (HiiHandles != NULL)); HiiHandle = gDeviceManagerPrivate.HiiHandle; diff --git a/MdeModulePkg/Universal/BdsDxe/Hotkey.c b/MdeModulePkg/Universal/BdsDxe/Hotkey.c index 9efba6d730..bfad7ce755 100644 --- a/MdeModulePkg/Universal/BdsDxe/Hotkey.c +++ b/MdeModulePkg/Universal/BdsDxe/Hotkey.c @@ -308,7 +308,7 @@ UnregisterHotkey ( information for the key that was pressed. @retval EFI_SUCCESS KeyData is successfully processed. - + @return EFI_NOT_FOUND Fail to find boot option variable. **/ EFI_STATUS HotkeyCallback ( @@ -344,6 +344,7 @@ HotkeyCallback ( // // Is this Key Stroke we are waiting for? // + ASSERT (Hotkey->WaitingKey < (sizeof (Hotkey->KeyData) / sizeof (Hotkey->KeyData[0]))); HotkeyData = &Hotkey->KeyData[Hotkey->WaitingKey]; if ((KeyData->Key.ScanCode == HotkeyData->Key.ScanCode) && (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) && @@ -389,6 +390,9 @@ HotkeyCallback ( UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", Hotkey->BootOptionNumber); BootOption = BdsLibVariableToOption (&BootLists, Buffer); + if (BootOption == NULL) { + return EFI_NOT_FOUND; + } BootOption->BootCurrent = Hotkey->BootOptionNumber; BdsLibConnectDevicePath (BootOption->DevicePath); diff --git a/MdeModulePkg/Universal/BdsDxe/MemoryTest.c b/MdeModulePkg/Universal/BdsDxe/MemoryTest.c index 747ebf72c6..fabdf24310 100644 --- a/MdeModulePkg/Universal/BdsDxe/MemoryTest.c +++ b/MdeModulePkg/Universal/BdsDxe/MemoryTest.c @@ -86,7 +86,7 @@ PlatformBdsShowProgress ( if (GraphicsOutput != NULL) { SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; - } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { + } else if (UgaDraw != NULL) { Status = UgaDraw->GetMode ( UgaDraw, &SizeOfX, -- cgit v1.2.3