From f9a6965f4e88662bc419532b1cb4fad335162a0a Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 4 Sep 2023 18:47:39 -0500 Subject: [PATCH] OcFileLib: Use ReadUnaligned32 for MBR table checks --- Library/OcFileLib/DiskMisc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Library/OcFileLib/DiskMisc.c b/Library/OcFileLib/DiskMisc.c index 0c4eb67c75d..ca4407a5133 100644 --- a/Library/OcFileLib/DiskMisc.c +++ b/Library/OcFileLib/DiskMisc.c @@ -881,12 +881,14 @@ OcGetDiskMbrTable ( if (CheckPartitions) { if ( (Mbr->Partition[0].OSIndicator == PMBR_GPT_PARTITION) - && (*((UINT32 *)Mbr->Partition[0].StartingLBA) == 0x01) - && (*((UINT32 *)Mbr->Partition[0].SizeInLBA) != 0)) + && (ReadUnaligned32 ((UINT32 *)Mbr->Partition[0].StartingLBA) == 0x01) + && (ReadUnaligned32 ((UINT32 *)Mbr->Partition[0].SizeInLBA) != 0)) { IsProtectiveMbr = TRUE; for (Index = 1; Index < MAX_MBR_PARTITIONS; Index++) { - if ((*((UINT32 *)Mbr->Partition[Index].StartingLBA) != 0) || (*((UINT32 *)Mbr->Partition[Index].SizeInLBA) != 0)) { + if ( (ReadUnaligned32 ((UINT32 *)Mbr->Partition[Index].StartingLBA) != 0) + || (ReadUnaligned32 ((UINT32 *)Mbr->Partition[Index].SizeInLBA) != 0)) + { IsProtectiveMbr = FALSE; break; } @@ -958,8 +960,8 @@ OcDiskGetMbrPartitionIndex ( Status = EFI_NOT_FOUND; for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) { - if ( (*((UINT32 *)Mbr->Partition[Index].StartingLBA) == HdNode->PartitionStart) - && (*((UINT32 *)Mbr->Partition[Index].SizeInLBA) == HdNode->PartitionSize)) + if ( (ReadUnaligned32 ((UINT32 *)Mbr->Partition[Index].StartingLBA) == HdNode->PartitionStart) + && (ReadUnaligned32 ((UINT32 *)Mbr->Partition[Index].SizeInLBA) == HdNode->PartitionSize)) { *PartitionIndex = Index; Status = EFI_SUCCESS;