mirror of
				https://gitlab.com/qemu-project/edk2.git
				synced 2025-10-30 07:56:39 +08:00 
			
		
		
		
	ShellPkg: AcpiView: Fix CodeQL Error
When removing ARM32 code from edk2, a CodeQL error in AcpiView (pointer used without null check) was flagged in GH. This updates the code to eliminate the duplicate code in that function and instead call EfiGetSystemConfigurationTable. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This commit is contained in:
		 Oliver Smith-Denny
					Oliver Smith-Denny
				
			
				
					committed by
					
						![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
			
				
	
			
			
			![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
						parent
						
							12797dd337
						
					
				
				
					commit
					f451d187c3
				
			| @ -192,25 +192,16 @@ AcpiView ( | ||||
|   IN EFI_SYSTEM_TABLE  *SystemTable | ||||
|   ) | ||||
| { | ||||
|   EFI_STATUS               Status; | ||||
|   UINTN                    Index; | ||||
|   EFI_CONFIGURATION_TABLE  *EfiConfigurationTable; | ||||
|   BOOLEAN                  FoundAcpiTable; | ||||
|   UINTN                    OriginalAttribute; | ||||
|   UINTN                    PrintAttribute; | ||||
|   EREPORT_OPTION           ReportOption; | ||||
|   UINT8                    *RsdpPtr; | ||||
|   UINT32                   RsdpLength; | ||||
|   UINT8                    RsdpRevision; | ||||
|   PARSE_ACPI_TABLE_PROC    RsdpParserProc; | ||||
|   BOOLEAN                  Trace; | ||||
|   SELECTED_ACPI_TABLE      *SelectedTable; | ||||
|  | ||||
|   // | ||||
|   // set local variables to suppress incorrect compiler/analyzer warnings | ||||
|   // | ||||
|   EfiConfigurationTable = NULL; | ||||
|   OriginalAttribute     = 0; | ||||
|   EFI_STATUS             Status; | ||||
|   UINTN                  OriginalAttribute; | ||||
|   UINTN                  PrintAttribute; | ||||
|   EREPORT_OPTION         ReportOption; | ||||
|   UINT8                  *RsdpPtr; | ||||
|   UINT32                 RsdpLength; | ||||
|   UINT8                  RsdpRevision; | ||||
|   PARSE_ACPI_TABLE_PROC  RsdpParserProc; | ||||
|   BOOLEAN                Trace; | ||||
|   SELECTED_ACPI_TABLE    *SelectedTable; | ||||
|  | ||||
|   // Reset Table counts | ||||
|   mTableCount    = 0; | ||||
| @ -223,60 +214,12 @@ AcpiView ( | ||||
|   // Retrieve the user selection of ACPI table to process | ||||
|   GetSelectedAcpiTable (&SelectedTable); | ||||
|  | ||||
|   // Search the table for an entry that matches the ACPI Table Guid | ||||
|   FoundAcpiTable = FALSE; | ||||
|   for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) { | ||||
|     if (CompareGuid ( | ||||
|           &gEfiAcpiTableGuid, | ||||
|           &(SystemTable->ConfigurationTable[Index].VendorGuid) | ||||
|           )) | ||||
|     { | ||||
|       EfiConfigurationTable = &SystemTable->ConfigurationTable[Index]; | ||||
|       FoundAcpiTable        = TRUE; | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|   Status = EfiGetSystemConfigurationTable ( | ||||
|              &gEfiAcpiTableGuid, | ||||
|              (VOID **)&RsdpPtr | ||||
|              ); | ||||
|  | ||||
|   if (FoundAcpiTable) { | ||||
|     RsdpPtr = (UINT8 *)EfiConfigurationTable->VendorTable; | ||||
|  | ||||
|     // The RSDP revision is 1 byte starting at offset 15 | ||||
|     RsdpRevision = *(RsdpPtr + RSDP_REVISION_OFFSET); | ||||
|  | ||||
|     if (RsdpRevision < 2) { | ||||
|       Print ( | ||||
|         L"ERROR: RSDP version less than 2 is not supported.\n" | ||||
|         ); | ||||
|       return EFI_UNSUPPORTED; | ||||
|     } | ||||
|  | ||||
|  #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) | ||||
|     if (GetMandatoryTableValidate ()) { | ||||
|       ArmSbbrResetTableCounts (); | ||||
|     } | ||||
|  | ||||
|  #endif | ||||
|  | ||||
|     // The RSDP length is 4 bytes starting at offset 20 | ||||
|     RsdpLength = *(UINT32 *)(RsdpPtr + RSDP_LENGTH_OFFSET); | ||||
|  | ||||
|     Trace = ProcessTableReportOptions (RSDP_TABLE_INFO, RsdpPtr, RsdpLength); | ||||
|  | ||||
|     Status = GetParser (RSDP_TABLE_INFO, &RsdpParserProc); | ||||
|     if (EFI_ERROR (Status)) { | ||||
|       Print ( | ||||
|         L"ERROR: No registered parser found for RSDP.\n" | ||||
|         ); | ||||
|       return Status; | ||||
|     } | ||||
|  | ||||
|     RsdpParserProc ( | ||||
|       Trace, | ||||
|       RsdpPtr, | ||||
|       RsdpLength, | ||||
|       RsdpRevision | ||||
|       ); | ||||
|   } else { | ||||
|   if (EFI_ERROR (Status)) { | ||||
|     IncrementErrorCount (); | ||||
|     Print ( | ||||
|       L"ERROR: Failed to find ACPI Table Guid in System Configuration Table.\n" | ||||
| @ -284,6 +227,43 @@ AcpiView ( | ||||
|     return EFI_NOT_FOUND; | ||||
|   } | ||||
|  | ||||
|   // The RSDP revision is 1 byte starting at offset 15 | ||||
|   RsdpRevision = *(RsdpPtr + RSDP_REVISION_OFFSET); | ||||
|  | ||||
|   if (RsdpRevision < 2) { | ||||
|     Print ( | ||||
|       L"ERROR: RSDP version less than 2 is not supported.\n" | ||||
|       ); | ||||
|     return EFI_UNSUPPORTED; | ||||
|   } | ||||
|  | ||||
|  #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) | ||||
|   if (GetMandatoryTableValidate ()) { | ||||
|     ArmSbbrResetTableCounts (); | ||||
|   } | ||||
|  | ||||
|  #endif | ||||
|  | ||||
|   // The RSDP length is 4 bytes starting at offset 20 | ||||
|   RsdpLength = *(UINT32 *)(RsdpPtr + RSDP_LENGTH_OFFSET); | ||||
|  | ||||
|   Trace = ProcessTableReportOptions (RSDP_TABLE_INFO, RsdpPtr, RsdpLength); | ||||
|  | ||||
|   Status = GetParser (RSDP_TABLE_INFO, &RsdpParserProc); | ||||
|   if (EFI_ERROR (Status)) { | ||||
|     Print ( | ||||
|       L"ERROR: No registered parser found for RSDP.\n" | ||||
|       ); | ||||
|     return Status; | ||||
|   } | ||||
|  | ||||
|   RsdpParserProc ( | ||||
|     Trace, | ||||
|     RsdpPtr, | ||||
|     RsdpLength, | ||||
|     RsdpRevision | ||||
|     ); | ||||
|  | ||||
|  #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64) | ||||
|   if (GetMandatoryTableValidate ()) { | ||||
|     ArmSbbrReqsValidate ((ARM_SBBR_VERSION)GetMandatoryTableSpec ()); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user