Skip to content

Commit

Permalink
OcFileLib: Use ReadUnaligned32 for MBR table checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldfish64 committed Sep 4, 2023
1 parent 7e8555a commit f9a6965
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Library/OcFileLib/DiskMisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f9a6965

Please sign in to comment.