From 14a7206c5b7b8fd13537d4fbbe9d6d7a6249dd88 Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Sun, 15 Sep 2019 21:27:19 +0300 Subject: [PATCH] some fighting with idiotic ASSERTs Signed-off-by: Sergey Isakov --- BaseTools/Conf/tools_def.template | 6 +-- Conf/tools_def.txt | 2 +- .../MemoryAllocationLib.c | 22 +++++---- .../DxeSecurityManagementLib.c | 18 ++++++++ .../Library/UefiBootManagerLib/BmBoot.c | 46 +++++++++++++++---- .../Library/UefiBootManagerLib/BmHotkey.c | 1 + MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 12 +++-- .../Library/UefiSortLib/UefiSortLib.c | 25 ++++++++-- MdePkg/Library/BaseLib/String.c | 7 ++- .../SynchronizationGcc.c | 15 +++++- MdePkg/Library/DxeHobLib/HobLib.c | 3 ++ MdePkg/Library/DxePcdLib/DxePcdLib.c | 36 ++++++++++++--- .../UefiHandleParsingLib.c | 5 +- .../UefiShellCommandLib/UefiShellCommandLib.c | 9 ++-- .../Library/UefiShellLevel1CommandsLib/For.c | 3 ++ .../Library/UefiShellLevel1CommandsLib/If.c | 7 +++ .../UefiShellLevel1CommandsLib/Shift.c | 6 +++ ShellPkg/Library/UefiShellLib/UefiShellLib.c | 6 +-- 18 files changed, 184 insertions(+), 45 deletions(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 248ceb676..9dd45f441 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -2008,12 +2008,10 @@ DEFINE GCC_X64_RC_FLAGS = -I binary -O elf64-x86-64 -B i386 --re DEFINE GCC_ARM_RC_FLAGS = -I binary -O elf32-littlearm -B arm --rename-section .data=.hii DEFINE GCC_AARCH64_RC_FLAGS = -I binary -O elf64-littleaarch64 -B aarch64 --rename-section .data=.hii -DEFINE GCC48_ALL_CC_FLAGS = -g -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -Wno-unused-const-variable -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings +DEFINE GCC48_ALL_CC_FLAGS = -g -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings DEFINE GCC48_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20 - DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector -mabi=ms "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -Os -flto - DEFINE GCC48_IA32_X64_ASLDLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable DEFINE GCC48_IA32_X64_DLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive DEFINE GCC48_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON) @@ -2081,7 +2079,7 @@ DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS) DEFINE GCC5_ASLCC_FLAGS = DEF(GCC49_ASLCC_FLAGS) -fno-lto DEFINE GCC53_IA32_CC_FLAGS = DEF(GCC49_IA32_CC_FLAGS) -DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS) +DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS) -Wno-unused-but-set-variable DEFINE GCC53_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections,-z,common-page-size=0x40,--defsym=PECOFF_HEADER_SIZE=0x280,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds DEFINE GCC53_IA32_X64_ASLDLINK_FLAGS = DEF(GCC53_IA32_X64_DLINK_COMMON),--entry,ReferenceAcpiTable,-u,ReferenceAcpiTable diff --git a/Conf/tools_def.txt b/Conf/tools_def.txt index 0945b5efc..9dd45f441 100644 --- a/Conf/tools_def.txt +++ b/Conf/tools_def.txt @@ -2079,7 +2079,7 @@ DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS) DEFINE GCC5_ASLCC_FLAGS = DEF(GCC49_ASLCC_FLAGS) -fno-lto DEFINE GCC53_IA32_CC_FLAGS = DEF(GCC49_IA32_CC_FLAGS) -DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS) +DEFINE GCC53_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS) -Wno-unused-but-set-variable DEFINE GCC53_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections,-z,common-page-size=0x40,--defsym=PECOFF_HEADER_SIZE=0x280,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds DEFINE GCC53_IA32_X64_ASLDLINK_FLAGS = DEF(GCC53_IA32_X64_DLINK_COMMON),--entry,ReferenceAcpiTable,-u,ReferenceAcpiTable diff --git a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c index cecf2ddbe..8f2985f4f 100644 --- a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c @@ -181,11 +181,13 @@ FreePages ( IN UINTN Pages ) { - EFI_STATUS Status; +// EFI_STATUS Status; ASSERT (Pages != 0); - Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); - ASSERT_EFI_ERROR (Status); + if (Pages != 0) { +/* Status = */CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); + } +// ASSERT_EFI_ERROR (Status); } /** @@ -421,11 +423,13 @@ FreeAlignedPages ( IN UINTN Pages ) { - EFI_STATUS Status; +// EFI_STATUS Status; ASSERT (Pages != 0); - Status = CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); - ASSERT_EFI_ERROR (Status); + if (Pages != 0) { +/* Status = */ CoreFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); + } +// ASSERT_EFI_ERROR (Status); } /** @@ -1046,9 +1050,9 @@ FreePool ( IN VOID *Buffer ) { - EFI_STATUS Status; +// EFI_STATUS Status; - Status = CoreFreePool (Buffer); - ASSERT_EFI_ERROR (Status); +/* Status = */ CoreFreePool (Buffer); +// ASSERT_EFI_ERROR (Status); } diff --git a/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c b/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c index b541dbab3..a97c3ff28 100644 --- a/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c +++ b/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c @@ -146,11 +146,17 @@ RegisterSecurityHandler ( EFI_STATUS Status; ASSERT (SecurityHandler != NULL); + if (!SecurityHandler) { + return EFI_INVALID_PARAMETER; + } // // Make sure AuthenticationOperation is valid in the register order. // ASSERT (CheckAuthenticationOperation (mCurrentAuthOperation, AuthenticationOperation)); + if (!CheckAuthenticationOperation (mCurrentAuthOperation, AuthenticationOperation)) { + return EFI_INVALID_PARAMETER; + } mCurrentAuthOperation = mCurrentAuthOperation | AuthenticationOperation; // @@ -162,6 +168,9 @@ RegisterSecurityHandler ( // Status = ReallocateSecurityHandlerTable(); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return Status; + } } // @@ -399,11 +408,17 @@ RegisterSecurity2Handler ( EFI_STATUS Status; ASSERT (Security2Handler != NULL); + if (!Security2Handler) { + return EFI_INVALID_PARAMETER; + } // // Make sure AuthenticationOperation is valid in the register order. // ASSERT (CheckAuthentication2Operation (mCurrentAuthOperation2, AuthenticationOperation)); + if (!CheckAuthentication2Operation (mCurrentAuthOperation2, AuthenticationOperation)) { + return EFI_INVALID_PARAMETER; + } mCurrentAuthOperation2 = mCurrentAuthOperation2 | AuthenticationOperation; // @@ -415,6 +430,9 @@ RegisterSecurity2Handler ( // Status = ReallocateSecurity2HandlerTable(); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return Status; + } } // diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index 952033fc8..a432990d5 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1286,6 +1286,9 @@ BmGetRamDiskMemoryInfo ( UINT64 EndingAddr; ASSERT (RamDiskDevicePath != NULL); + if (!RamDiskDevicePath) { + return NULL; + } *RamDiskSizeInPages = 0; @@ -1294,6 +1297,9 @@ BmGetRamDiskMemoryInfo ( // Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &RamDiskDevicePath, &Handle); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } ASSERT ((DevicePathType (RamDiskDevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType (RamDiskDevicePath) == MEDIA_RAM_DISK_DP)); StartingAddr = ReadUnaligned64 ((UINT64 *) ((MEDIA_RAM_DISK_DEVICE_PATH *) RamDiskDevicePath)->StartingAddr); @@ -1321,6 +1327,10 @@ BmDestroyRamDisk ( UINTN RamDiskSizeInPages; ASSERT (RamDiskDevicePath != NULL); + if (!RamDiskDevicePath) { + return; + } + RamDiskBuffer = BmGetRamDiskMemoryInfo (RamDiskDevicePath, &RamDiskSizeInPages); @@ -1330,9 +1340,12 @@ BmDestroyRamDisk ( if (mRamDisk == NULL) { Status = gBS->LocateProtocol (&gEfiRamDiskProtocolGuid, NULL, (VOID *) &mRamDisk); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return; + } } - Status = mRamDisk->Unregister (RamDiskDevicePath); - ASSERT_EFI_ERROR (Status); +/* Status = */mRamDisk->Unregister (RamDiskDevicePath); +// ASSERT_EFI_ERROR (Status); FreePages (RamDiskBuffer, RamDiskSizeInPages); } @@ -1366,6 +1379,10 @@ BmExpandLoadFile ( EFI_OPEN_PROTOCOL_GET_PROTOCOL ); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } + FileBuffer = NULL; BufferSize = 0; @@ -1534,6 +1551,9 @@ BmGetNextLoadOptionDevicePath ( EFI_STATUS Status; ASSERT (FilePath != NULL); + if (!FilePath) { + return NULL; + } // // Boot from media device by adding a default file name \EFI\BOOT\BOOT{machine type short-name}.EFI @@ -2292,6 +2312,7 @@ EfiBootManagerRefreshAllBootOption ( // Deleting variable with current variable implementation shouldn't fail. // ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) break; } } } @@ -2404,6 +2425,9 @@ BmRegisterBootManagerMenu ( (VOID **) &LoadedImage ); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } DevicePath = AppendDevicePathNode ( DevicePathFromHandle (LoadedImage->DeviceHandle), (EFI_DEVICE_PATH_PROTOCOL *) &FileNode @@ -2422,11 +2446,16 @@ BmRegisterBootManagerMenu ( 0 ); ASSERT_EFI_ERROR (Status); - FreePool (DevicePath); + if (EFI_ERROR (Status)) { + return Status; + } + if (DevicePath) { + FreePool (DevicePath); + } if (Description != NULL) { FreePool (Description); } - +/* DEBUG_CODE ( EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; UINTN BootOptionCount; @@ -2435,7 +2464,7 @@ BmRegisterBootManagerMenu ( ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1); EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); ); - +*/ return EfiBootManagerAddLoadOptionVariable (BootOption, 0); } @@ -2457,7 +2486,7 @@ EfiBootManagerGetBootManagerMenu ( EFI_BOOT_MANAGER_LOAD_OPTION *BootOption ) { - EFI_STATUS Status; +// EFI_STATUS Status; UINTN BootOptionCount; EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; UINTN Index; @@ -2466,7 +2495,7 @@ EfiBootManagerGetBootManagerMenu ( for (Index = 0; Index < BootOptionCount; Index++) { if (BmIsBootManagerMenuFilePath (BootOptions[Index].FilePath)) { - Status = EfiBootManagerInitializeLoadOption ( + /*Status = */EfiBootManagerInitializeLoadOption ( BootOption, BootOptions[Index].OptionNumber, BootOptions[Index].OptionType, @@ -2476,7 +2505,8 @@ EfiBootManagerGetBootManagerMenu ( BootOptions[Index].OptionalData, BootOptions[Index].OptionalDataSize ); - ASSERT_EFI_ERROR (Status); + // ASSERT_EFI_ERROR (Status); + break; } } diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c index c2d1447f5..fdba29af4 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -683,6 +683,7 @@ BmProcessKeyOption ( for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) continue; BmRegisterHotkeyNotify (TxtInEx, Hotkey); } } diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 564169bc1..5f39d1d49 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -152,6 +152,9 @@ HiiAddPackages ( UINT8 *Data; ASSERT (PackageListGuid != NULL); + if (!PackageListGuid) { + return NULL; + } // // Calculate the length of all the packages in the variable argument list @@ -251,11 +254,14 @@ HiiRemovePackages ( IN EFI_HII_HANDLE HiiHandle ) { - EFI_STATUS Status; +// EFI_STATUS Status; ASSERT (HiiHandle != NULL); - Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle); - ASSERT_EFI_ERROR (Status); + if (!HiiHandle) { + return; + } +/* Status = */gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle); +// ASSERT_EFI_ERROR (Status); } diff --git a/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c b/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c index 46dc44363..9f8132bcf 100644 --- a/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c +++ b/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c @@ -230,6 +230,16 @@ DevicePathCompare ( (VOID**)&mUnicodeCollation); ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + return -1; + } +/* if (EFI_ERROR(Status)) { + Status = gBS->LocateProtocol( + &gEfiUnicodeCollationProtocolGuid, + NULL, + (VOID**)&mUnicodeCollation); + + } */ } TextPath1 = ConvertDevicePathToText( @@ -247,10 +257,14 @@ DevicePathCompare ( } else if (TextPath2 == NULL) { RetVal = 1; } else { - RetVal = mUnicodeCollation->StriColl( - mUnicodeCollation, - TextPath1, - TextPath2); + if (mUnicodeCollation) { + RetVal = mUnicodeCollation->StriColl( + mUnicodeCollation, + TextPath1, + TextPath2); + } else { + RetVal = 1; + } } USL_FREE_NON_NULL(TextPath1); @@ -284,6 +298,9 @@ StringNoCaseCompare ( (VOID**)&mUnicodeCollation); ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + return -1; + } } return (mUnicodeCollation->StriColl( diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c index f4b00ac47..7d459d1c8 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -43,13 +43,16 @@ StrCpy ( ) { CHAR16 *ReturnValue; - INTN DestMax; +// INTN DestMax; // // Destination cannot be NULL // ASSERT (Destination != NULL); ASSERT (((UINTN) Destination & BIT0) == 0); + if (!Destination || !Source) { + return NULL; + } // // Destination and source cannot overlap @@ -57,7 +60,7 @@ StrCpy ( ASSERT ((UINTN)(Destination - Source) > StrLen (Source)); ASSERT ((UINTN)(Source - Destination) > StrLen (Source)); - DestMax = StrLen (Destination); +// DestMax = StrLen (Destination); ReturnValue = Destination; while (*Source != 0) { diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c index 466775e60..890fdba88 100644 --- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c +++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c @@ -154,7 +154,8 @@ AcquireSpinLock ( Delta += Cycle; } Total += Delta; - ASSERT (Total < Timeout); + // ASSERT (Total < Timeout); + if (Total >= Timeout) break; } } return SpinLock; @@ -187,9 +188,15 @@ AcquireSpinLockOrFail ( VOID *Result; ASSERT (SpinLock != NULL); + if (!SpinLock) { + return FALSE; + } LockValue = *SpinLock; ASSERT (LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED); + if (!(LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED)) { + return FALSE; + } _ReadWriteBarrier (); Result = InterlockedCompareExchangePointer ( @@ -225,9 +232,15 @@ ReleaseSpinLock ( SPIN_LOCK LockValue; ASSERT (SpinLock != NULL); + if (!SpinLock) { + return NULL; + } LockValue = *SpinLock; ASSERT (LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED); + if (!(LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED)) { + return NULL; + } _ReadWriteBarrier (); *SpinLock = SPIN_LOCK_RELEASED; diff --git a/MdePkg/Library/DxeHobLib/HobLib.c b/MdePkg/Library/DxeHobLib/HobLib.c index bf2470f6e..ba1025aed 100644 --- a/MdePkg/Library/DxeHobLib/HobLib.c +++ b/MdePkg/Library/DxeHobLib/HobLib.c @@ -46,6 +46,9 @@ GetHobList ( if (mHobList == NULL) { Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &mHobList); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } ASSERT (mHobList != NULL); } return mHobList; diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c index 6e3e4e706..46c98249a 100644 --- a/MdePkg/Library/DxePcdLib/DxePcdLib.c +++ b/MdePkg/Library/DxePcdLib/DxePcdLib.c @@ -45,6 +45,9 @@ GetPiPcdProtocol ( // Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } ASSERT (mPiPcd != NULL); } return mPiPcd; @@ -70,6 +73,9 @@ GetPcdProtocol ( // Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } ASSERT (mPcd != NULL); } return mPcd; @@ -90,6 +96,9 @@ GetPiPcdInfoProtocolPointer ( if (mPiPcdInfo == NULL) { Status = gBS->LocateProtocol (&gEfiGetPcdInfoProtocolGuid, NULL, (VOID **)&mPiPcdInfo); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } ASSERT (mPiPcdInfo != NULL); } return mPiPcdInfo; @@ -110,6 +119,9 @@ GetPcdInfoProtocolPointer ( if (mPcdInfo == NULL) { Status = gBS->LocateProtocol (&gGetPcdInfoProtocolGuid, NULL, (VOID **)&mPcdInfo); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return NULL; + } ASSERT (mPcdInfo != NULL); } return mPcdInfo; @@ -1134,6 +1146,9 @@ LibPcdSetEx64S ( ) { ASSERT (Guid != NULL); + if (!Guid) { + return EFI_INVALID_PARAMETER; + } return GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value); } @@ -1172,6 +1187,9 @@ LibPcdSetExPtrS ( ASSERT (Guid != NULL); ASSERT (SizeOfBuffer != NULL); + if (!Guid || !SizeOfBuffer) { + return EFI_INVALID_PARAMETER; + } if (*SizeOfBuffer > 0) { ASSERT (Buffer != NULL); @@ -1205,6 +1223,9 @@ LibPcdSetExBoolS ( ) { ASSERT (Guid != NULL); + if (!Guid) { + return EFI_INVALID_PARAMETER; + } return GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value); } @@ -1233,12 +1254,12 @@ LibPcdCallbackOnSet ( IN PCD_CALLBACK NotificationFunction ) { - EFI_STATUS Status; +// EFI_STATUS Status; ASSERT (NotificationFunction != NULL); - Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction); - ASSERT_EFI_ERROR (Status); +/* Status = */GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction); +// ASSERT_EFI_ERROR (Status); return; } @@ -1266,12 +1287,12 @@ LibPcdCancelCallback ( IN PCD_CALLBACK NotificationFunction ) { - EFI_STATUS Status; +// EFI_STATUS Status; ASSERT (NotificationFunction != NULL); - Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction); - ASSERT_EFI_ERROR (Status); +/* Status = */GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction); +// ASSERT_EFI_ERROR (Status); return; } @@ -1308,6 +1329,9 @@ LibPcdGetNextToken ( Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber); ASSERT (!EFI_ERROR (Status) || TokenNumber == 0); + if (EFI_ERROR (Status)) { + TokenNumber = 0; + } return TokenNumber; } diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c index a81d5bc91..3d75511a5 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c @@ -808,6 +808,9 @@ DriverEfiVersionProtocolDumpInformation( (VOID**)&DriverEfiVersion); ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + return NULL; + } RetVal = AllocateZeroPool(VersionStringSize); if (RetVal != NULL) { @@ -2696,7 +2699,7 @@ GetBestLanguageForDriver ( BestLanguage = GetBestLanguage( SupportedLanguages, - Iso639Language, + Iso639Language, "", (InputLanguage != NULL) ? InputLanguage : "", (LanguageVariable != NULL) ? LanguageVariable : "", diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index 27e31b4ac..db9ea1df3 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -78,7 +78,7 @@ CommandInit( CHAR8 *BestLanguage = NULL; UINTN Index; EFI_STATUS Status; - CHAR8 *PlatformLang = NULL; + CHAR8 *PlatformLang = NULL; // BOOLEAN OldUC = FALSE; GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL); @@ -96,7 +96,7 @@ CommandInit( NumHandles = 0; Handles = NULL; } - // + // //Print(L"NumHandles UC %d\n", NumHandles); for (Index = 0; Index < NumHandles; Index++) { // @@ -121,7 +121,7 @@ CommandInit( // BestLanguage = GetBestLanguage ( Uc->SupportedLanguages, - FALSE, + FALSE, "", ((PlatformLang != NULL) ? PlatformLang : "en-US"), NULL @@ -1399,8 +1399,10 @@ ShellCommandCreateInitialMappingsAndPaths( // NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem); ASSERT(NewDefaultName != NULL); + if (!NewDefaultName) break; Status = ShellCommandAddMapItemAndUpdatePath(NewDefaultName, DevicePathList[Count], 0, TRUE); ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) break; FreePool(NewDefaultName); // @@ -1411,6 +1413,7 @@ ShellCommandCreateInitialMappingsAndPaths( Status = ShellCommandAddMapItemAndUpdatePath(NewConsistName, DevicePathList[Count], 0, FALSE); ASSERT_EFI_ERROR(Status); FreePool(NewConsistName); + if (EFI_ERROR(Status)) break; } } diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c index 982497714..f73164c74 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c @@ -73,6 +73,9 @@ ShellCommandRunEndFor ( Status = CommandInit(); ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + return Status; + } if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"endfor"); diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c index 35c5ca683..c1df8318e 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c @@ -1002,6 +1002,9 @@ ShellCommandRunElse ( Status = CommandInit (); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return Status; + } if (gEfiShellParametersProtocol->Argc > 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"if"); @@ -1080,6 +1083,10 @@ ShellCommandRunEndIf ( Status = CommandInit (); ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return Status; + } + if (gEfiShellParametersProtocol->Argc > 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"if"); diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c index 08c54f8f7..f66db54af 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c @@ -34,6 +34,9 @@ ShellCommandRunShift ( Status = CommandInit(); ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + return Status; + } if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"shift"); @@ -42,6 +45,9 @@ ShellCommandRunShift ( CurrentScriptFile = ShellCommandGetCurrentScriptFile(); ASSERT(CurrentScriptFile != NULL); + if (!CurrentScriptFile) { + return (SHELL_UNSUPPORTED); + } if (CurrentScriptFile->Argc < 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"shift"); diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 963d9a71b..7fcd614dc 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -380,7 +380,7 @@ EFIAPI ShellInitialize ( ) { - EFI_STATUS Status; +// EFI_STATUS Status; // // if auto initialize is not false then skip @@ -392,8 +392,8 @@ ShellInitialize ( // // deinit the current stuff // - Status = ShellLibDestructor (gImageHandle, gST); - ASSERT_EFI_ERROR (Status); +/* Status = */ShellLibDestructor (gImageHandle, gST); +// ASSERT_EFI_ERROR (Status); // // init the new stuff