mirror of https://github.com/acidanthera/audk.git
ShellPkg: Fix conditionally uninitialized variables
Fixes CodeQL alerts for CWE-457: https://cwe.mitre.org/data/definitions/457.html Cc: Erich McMillan <emcmillan@microsoft.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Zhichao Gao <zhichao.gao@intel.com> Co-authored-by: Erich McMillan <emcmillan@microsoft.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com> Reviewed-by: Oliver Smith-Denny <osd@smith-denny.com>
This commit is contained in:
parent
7dc182ed1e
commit
11dd44dfbe
|
@ -1300,6 +1300,7 @@ DoStartupScript (
|
||||||
CHAR16 *FullFileStringPath;
|
CHAR16 *FullFileStringPath;
|
||||||
UINTN NewSize;
|
UINTN NewSize;
|
||||||
|
|
||||||
|
CalleeStatus = EFI_SUCCESS;
|
||||||
Key.UnicodeChar = CHAR_NULL;
|
Key.UnicodeChar = CHAR_NULL;
|
||||||
Key.ScanCode = 0;
|
Key.ScanCode = 0;
|
||||||
|
|
||||||
|
|
|
@ -735,50 +735,52 @@ EfiShellGetDeviceName (
|
||||||
//
|
//
|
||||||
// Now check the parent controller using this as the child.
|
// Now check the parent controller using this as the child.
|
||||||
//
|
//
|
||||||
if (DeviceNameToReturn == NULL) {
|
Status = PARSE_HANDLE_DATABASE_PARENTS (DeviceHandle, &ParentControllerCount, &ParentControllerBuffer);
|
||||||
PARSE_HANDLE_DATABASE_PARENTS (DeviceHandle, &ParentControllerCount, &ParentControllerBuffer);
|
if ((DeviceNameToReturn == NULL) && !EFI_ERROR (Status)) {
|
||||||
for (LoopVar = 0; LoopVar < ParentControllerCount; LoopVar++) {
|
for (LoopVar = 0; LoopVar < ParentControllerCount; LoopVar++) {
|
||||||
PARSE_HANDLE_DATABASE_UEFI_DRIVERS (ParentControllerBuffer[LoopVar], &ParentDriverCount, &ParentDriverBuffer);
|
Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (ParentControllerBuffer[LoopVar], &ParentDriverCount, &ParentDriverBuffer);
|
||||||
for (HandleCount = 0; HandleCount < ParentDriverCount; HandleCount++) {
|
if (!EFI_ERROR (Status)) {
|
||||||
//
|
for (HandleCount = 0; HandleCount < ParentDriverCount; HandleCount++) {
|
||||||
// try using that driver's component name with controller and our driver as the child.
|
//
|
||||||
//
|
// try using that driver's component name with controller and our driver as the child.
|
||||||
Status = gBS->OpenProtocol (
|
//
|
||||||
ParentDriverBuffer[HandleCount],
|
|
||||||
&gEfiComponentName2ProtocolGuid,
|
|
||||||
(VOID **)&CompName2,
|
|
||||||
gImageHandle,
|
|
||||||
NULL,
|
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
||||||
);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
ParentDriverBuffer[HandleCount],
|
ParentDriverBuffer[HandleCount],
|
||||||
&gEfiComponentNameProtocolGuid,
|
&gEfiComponentName2ProtocolGuid,
|
||||||
(VOID **)&CompName2,
|
(VOID **)&CompName2,
|
||||||
gImageHandle,
|
gImageHandle,
|
||||||
NULL,
|
NULL,
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
);
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
ParentDriverBuffer[HandleCount],
|
||||||
|
&gEfiComponentNameProtocolGuid,
|
||||||
|
(VOID **)&CompName2,
|
||||||
|
gImageHandle,
|
||||||
|
NULL,
|
||||||
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Lang = GetBestLanguageForDriver (CompName2->SupportedLanguages, Language, FALSE);
|
||||||
|
Status = CompName2->GetControllerName (CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);
|
||||||
|
FreePool (Lang);
|
||||||
|
Lang = NULL;
|
||||||
|
if (!EFI_ERROR (Status) && (DeviceNameToReturn != NULL)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
SHELL_FREE_NON_NULL (ParentDriverBuffer);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Lang = GetBestLanguageForDriver (CompName2->SupportedLanguages, Language, FALSE);
|
|
||||||
Status = CompName2->GetControllerName (CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);
|
|
||||||
FreePool (Lang);
|
|
||||||
Lang = NULL;
|
|
||||||
if (!EFI_ERROR (Status) && (DeviceNameToReturn != NULL)) {
|
if (!EFI_ERROR (Status) && (DeviceNameToReturn != NULL)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_FREE_NON_NULL (ParentDriverBuffer);
|
|
||||||
if (!EFI_ERROR (Status) && (DeviceNameToReturn != NULL)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_FREE_NON_NULL (ParentControllerBuffer);
|
SHELL_FREE_NON_NULL (ParentControllerBuffer);
|
||||||
|
|
|
@ -1399,10 +1399,11 @@ ShellCommandCreateInitialMappingsAndPaths (
|
||||||
CHAR16 *MapName;
|
CHAR16 *MapName;
|
||||||
SHELL_MAP_LIST *MapListItem;
|
SHELL_MAP_LIST *MapListItem;
|
||||||
|
|
||||||
SplitCurDir = NULL;
|
ConsistMappingTable = NULL;
|
||||||
MapName = NULL;
|
SplitCurDir = NULL;
|
||||||
MapListItem = NULL;
|
MapName = NULL;
|
||||||
HandleList = NULL;
|
MapListItem = NULL;
|
||||||
|
HandleList = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Reset the static members back to zero
|
// Reset the static members back to zero
|
||||||
|
@ -1458,32 +1459,35 @@ ShellCommandCreateInitialMappingsAndPaths (
|
||||||
//
|
//
|
||||||
PerformQuickSort (DevicePathList, Count, sizeof (EFI_DEVICE_PATH_PROTOCOL *), DevicePathCompare);
|
PerformQuickSort (DevicePathList, Count, sizeof (EFI_DEVICE_PATH_PROTOCOL *), DevicePathCompare);
|
||||||
|
|
||||||
ShellCommandConsistMappingInitialize (&ConsistMappingTable);
|
if (!EFI_ERROR (ShellCommandConsistMappingInitialize (&ConsistMappingTable))) {
|
||||||
//
|
|
||||||
// Assign new Mappings to all...
|
|
||||||
//
|
|
||||||
for (Count = 0; HandleList[Count] != NULL; Count++) {
|
|
||||||
//
|
//
|
||||||
// Get default name first
|
// Assign new Mappings to all...
|
||||||
//
|
//
|
||||||
NewDefaultName = ShellCommandCreateNewMappingName (MappingTypeFileSystem);
|
for (Count = 0; HandleList[Count] != NULL; Count++) {
|
||||||
ASSERT (NewDefaultName != NULL);
|
//
|
||||||
Status = ShellCommandAddMapItemAndUpdatePath (NewDefaultName, DevicePathList[Count], 0, TRUE);
|
// Get default name first
|
||||||
ASSERT_EFI_ERROR (Status);
|
//
|
||||||
FreePool (NewDefaultName);
|
NewDefaultName = ShellCommandCreateNewMappingName (MappingTypeFileSystem);
|
||||||
|
ASSERT (NewDefaultName != NULL);
|
||||||
//
|
Status = ShellCommandAddMapItemAndUpdatePath (NewDefaultName, DevicePathList[Count], 0, TRUE);
|
||||||
// Now do consistent name
|
|
||||||
//
|
|
||||||
NewConsistName = ShellCommandConsistMappingGenMappingName (DevicePathList[Count], ConsistMappingTable);
|
|
||||||
if (NewConsistName != NULL) {
|
|
||||||
Status = ShellCommandAddMapItemAndUpdatePath (NewConsistName, DevicePathList[Count], 0, FALSE);
|
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
FreePool (NewConsistName);
|
FreePool (NewDefaultName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Now do consistent name
|
||||||
|
//
|
||||||
|
NewConsistName = ShellCommandConsistMappingGenMappingName (DevicePathList[Count], ConsistMappingTable);
|
||||||
|
if (NewConsistName != NULL) {
|
||||||
|
Status = ShellCommandAddMapItemAndUpdatePath (NewConsistName, DevicePathList[Count], 0, FALSE);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
FreePool (NewConsistName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShellCommandConsistMappingUnInitialize (ConsistMappingTable);
|
if (ConsistMappingTable != NULL) {
|
||||||
|
ShellCommandConsistMappingUnInitialize (ConsistMappingTable);
|
||||||
|
}
|
||||||
|
|
||||||
SHELL_FREE_NON_NULL (HandleList);
|
SHELL_FREE_NON_NULL (HandleList);
|
||||||
SHELL_FREE_NON_NULL (DevicePathList);
|
SHELL_FREE_NON_NULL (DevicePathList);
|
||||||
|
@ -1626,12 +1630,12 @@ ShellCommandUpdateMapping (
|
||||||
//
|
//
|
||||||
PerformQuickSort (DevicePathList, Count, sizeof (EFI_DEVICE_PATH_PROTOCOL *), DevicePathCompare);
|
PerformQuickSort (DevicePathList, Count, sizeof (EFI_DEVICE_PATH_PROTOCOL *), DevicePathCompare);
|
||||||
|
|
||||||
ShellCommandConsistMappingInitialize (&ConsistMappingTable);
|
Status = ShellCommandConsistMappingInitialize (&ConsistMappingTable);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Assign new Mappings to remainders
|
// Assign new Mappings to remainders
|
||||||
//
|
//
|
||||||
for (Count = 0; !EFI_ERROR (Status) && HandleList[Count] != NULL && !EFI_ERROR (Status); Count++) {
|
for (Count = 0; !EFI_ERROR (Status) && HandleList[Count] != NULL; Count++) {
|
||||||
//
|
//
|
||||||
// Skip ones that already have
|
// Skip ones that already have
|
||||||
//
|
//
|
||||||
|
|
|
@ -158,7 +158,10 @@ ShellCommandRunDblk (
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShellConvertStringToUint64 (LbaString, &Lba, TRUE, FALSE);
|
if (EFI_ERROR (ShellConvertStringToUint64 (LbaString, &Lba, TRUE, FALSE))) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", LbaString);
|
||||||
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BlockCountString == NULL) {
|
if (BlockCountString == NULL) {
|
||||||
|
@ -169,12 +172,13 @@ ShellCommandRunDblk (
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShellConvertStringToUint64 (BlockCountString, &BlockCount, TRUE, FALSE);
|
if (!EFI_ERROR (ShellConvertStringToUint64 (BlockCountString, &BlockCount, TRUE, FALSE))) {
|
||||||
if (BlockCount > 0x10) {
|
if (BlockCount > 0x10) {
|
||||||
BlockCount = 0x10;
|
BlockCount = 0x10;
|
||||||
} else if (BlockCount == 0) {
|
} else if (BlockCount == 0) {
|
||||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString);
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockCountString);
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,13 @@ ShellCommandRunEfiDecompress (
|
||||||
|
|
||||||
if (ShellStatus == SHELL_SUCCESS) {
|
if (ShellStatus == SHELL_SUCCESS) {
|
||||||
Status = FileHandleGetSize (InFileHandle, &Temp64Bit);
|
Status = FileHandleGetSize (InFileHandle, &Temp64Bit);
|
||||||
ASSERT (Temp64Bit <= (UINT32)(-1));
|
|
||||||
InSize = (UINTN)Temp64Bit;
|
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
InBuffer = AllocateZeroPool (InSize);
|
if (!EFI_ERROR (Status)) {
|
||||||
|
ASSERT (Temp64Bit <= (UINT32)(-1));
|
||||||
|
InSize = (UINTN)Temp64Bit;
|
||||||
|
InBuffer = AllocateZeroPool (InSize);
|
||||||
|
}
|
||||||
|
|
||||||
if (InBuffer == NULL) {
|
if (InBuffer == NULL) {
|
||||||
Status = EFI_OUT_OF_RESOURCES;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -508,9 +508,10 @@ ShellCommandRunConnect (
|
||||||
Count = ShellCommandLineGetCount (Package);
|
Count = ShellCommandLineGetCount (Package);
|
||||||
|
|
||||||
if (Param1 != NULL) {
|
if (Param1 != NULL) {
|
||||||
Status = ShellConvertStringToUint64 (Param1, &Intermediate, TRUE, FALSE);
|
Status = ShellConvertStringToUint64 (Param1, &Intermediate, TRUE, FALSE);
|
||||||
Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
if (!EFI_ERROR (Status)) {
|
||||||
if (EFI_ERROR (Status)) {
|
Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
||||||
|
} else {
|
||||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1);
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1);
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
@ -519,9 +520,10 @@ ShellCommandRunConnect (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Param2 != NULL) {
|
if (Param2 != NULL) {
|
||||||
Status = ShellConvertStringToUint64 (Param2, &Intermediate, TRUE, FALSE);
|
Status = ShellConvertStringToUint64 (Param2, &Intermediate, TRUE, FALSE);
|
||||||
Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
if (!EFI_ERROR (Status)) {
|
||||||
if (EFI_ERROR (Status)) {
|
Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
||||||
|
} else {
|
||||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2);
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2);
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,12 +160,17 @@ ShellCommandRunDisconnect (
|
||||||
Param1 = ShellCommandLineGetRawValue (Package, 1);
|
Param1 = ShellCommandLineGetRawValue (Package, 1);
|
||||||
Param2 = ShellCommandLineGetRawValue (Package, 2);
|
Param2 = ShellCommandLineGetRawValue (Package, 2);
|
||||||
Param3 = ShellCommandLineGetRawValue (Package, 3);
|
Param3 = ShellCommandLineGetRawValue (Package, 3);
|
||||||
ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE);
|
if (!EFI_ERROR (ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE))) {
|
||||||
Handle1 = Param1 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate1) : NULL;
|
Handle1 = Param1 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate1) : NULL;
|
||||||
ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE);
|
}
|
||||||
Handle2 = Param2 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate2) : NULL;
|
|
||||||
ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE);
|
if (!EFI_ERROR (ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE))) {
|
||||||
Handle3 = Param3 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate3) : NULL;
|
Handle2 = Param2 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate2) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!EFI_ERROR (ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE))) {
|
||||||
|
Handle3 = Param3 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate3) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ((Param1 != NULL) && (Handle1 == NULL)) {
|
if ((Param1 != NULL) && (Handle1 == NULL)) {
|
||||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param1);
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param1);
|
||||||
|
|
|
@ -438,25 +438,22 @@ ShellCommandRunDrvDiag (
|
||||||
ControllerHandleStr = ShellCommandLineGetRawValue (Package, 2);
|
ControllerHandleStr = ShellCommandLineGetRawValue (Package, 2);
|
||||||
ChildHandleStr = ShellCommandLineGetRawValue (Package, 3);
|
ChildHandleStr = ShellCommandLineGetRawValue (Package, 3);
|
||||||
|
|
||||||
if (DriverHandleStr == NULL) {
|
if ((DriverHandleStr != NULL) && !EFI_ERROR (ShellConvertStringToUint64 (DriverHandleStr, &Intermediate, TRUE, FALSE))) {
|
||||||
Handle1 = NULL;
|
|
||||||
} else {
|
|
||||||
ShellConvertStringToUint64 (DriverHandleStr, &Intermediate, TRUE, FALSE);
|
|
||||||
Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
||||||
|
} else {
|
||||||
|
Handle1 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ControllerHandleStr == NULL) {
|
if ((ControllerHandleStr != NULL) && !EFI_ERROR (ShellConvertStringToUint64 (ControllerHandleStr, &Intermediate, TRUE, FALSE))) {
|
||||||
Handle2 = NULL;
|
|
||||||
} else {
|
|
||||||
ShellConvertStringToUint64 (ControllerHandleStr, &Intermediate, TRUE, FALSE);
|
|
||||||
Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
||||||
|
} else {
|
||||||
|
Handle2 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChildHandleStr == NULL) {
|
if ((ChildHandleStr != NULL) && !EFI_ERROR (ShellConvertStringToUint64 (ChildHandleStr, &Intermediate, TRUE, FALSE))) {
|
||||||
Handle3 = NULL;
|
|
||||||
} else {
|
|
||||||
ShellConvertStringToUint64 (ChildHandleStr, &Intermediate, TRUE, FALSE);
|
|
||||||
Handle3 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
Handle3 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
|
||||||
|
} else {
|
||||||
|
Handle3 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = DoDiagnostics (
|
Status = DoDiagnostics (
|
||||||
|
|
Loading…
Reference in New Issue