Skip to content

Commit

Permalink
Merge "fix(guid-partition): fix unaligned access in load_mbr_header()…
Browse files Browse the repository at this point in the history
…" into integration
  • Loading branch information
ManishVB-Arm authored and TrustedFirmware Code Review committed Jul 4, 2024
2 parents 0dc0fda + 21a77e0 commit 4b9be5a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/partition/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int load_mbr_header(uintptr_t image_handle, mbr_entry_t *mbr_entry)
{
size_t bytes_read;
int result;
mbr_entry_t *tmp;
mbr_entry_t tmp;

assert(mbr_entry != NULL);
/* MBR partition table is in LBA0. */
Expand All @@ -73,19 +73,19 @@ static int load_mbr_header(uintptr_t image_handle, mbr_entry_t *mbr_entry)
return -ENOENT;
}

tmp = (mbr_entry_t *)(&mbr_sector[MBR_PRIMARY_ENTRY_OFFSET]);
memcpy(&tmp, mbr_sector + MBR_PRIMARY_ENTRY_OFFSET, sizeof(tmp));

if (tmp->first_lba != 1) {
if (tmp.first_lba != 1) {
VERBOSE("MBR header may have an invalid first LBA\n");
return -EINVAL;
}

if ((tmp->sector_nums == 0) || (tmp->sector_nums == UINT32_MAX)) {
if ((tmp.sector_nums == 0) || (tmp.sector_nums == UINT32_MAX)) {
VERBOSE("MBR header entry has an invalid number of sectors\n");
return -EINVAL;
}

memcpy(mbr_entry, tmp, sizeof(mbr_entry_t));
memcpy(mbr_entry, &tmp, sizeof(mbr_entry_t));
return 0;
}

Expand Down

0 comments on commit 4b9be5a

Please sign in to comment.