Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partition: fix unaligned access in load_mbr_header() #9

Open
wants to merge 1 commit into
base: mtksoc
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions drivers/partition/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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 @@ -81,19 +81,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