Commit 16a83563 authored by Peter Jones's avatar Peter Jones

Kees' patch missed the offset adjustment to PEHdr.

In read_header, we adjust context->PEHdr's address by doshdr->e_lfanew.
If we're going to recompute that address, we have to adjust it here
too.
Signed-off-by: default avatarPeter Jones <pjones@redhat.com>
parent 47a9d2c9
......@@ -511,12 +511,8 @@ static EFI_STATUS generate_hash (char *data, int datasize_in,
EFI_IMAGE_SECTION_HEADER *SectionHeader = NULL;
EFI_IMAGE_SECTION_HEADER *SectionCache;
EFI_STATUS status = EFI_SUCCESS;
sha256ctxsize = Sha256GetContextSize();
sha256ctx = AllocatePool(sha256ctxsize);
sha1ctxsize = Sha1GetContextSize();
sha1ctx = AllocatePool(sha1ctxsize);
EFI_IMAGE_DOS_HEADER *DosHdr = (void *)data;
unsigned int PEHdr_offset = 0;
if (datasize_in < 0) {
Print(L"Invalid data size\n");
......@@ -524,6 +520,19 @@ static EFI_STATUS generate_hash (char *data, int datasize_in,
}
size = datasize = (unsigned int)datasize_in;
if (datasize <= sizeof (*DosHdr) ||
DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Print(L"Invalid signature\n");
return EFI_INVALID_PARAMETER;
}
PEHdr_offset = DosHdr->e_lfanew;
sha256ctxsize = Sha256GetContextSize();
sha256ctx = AllocatePool(sha256ctxsize);
sha1ctxsize = Sha1GetContextSize();
sha1ctx = AllocatePool(sha1ctxsize);
if (!sha256ctx || !sha1ctx) {
Print(L"Unable to allocate memory for hash context\n");
return EFI_OUT_OF_RESOURCES;
......@@ -590,6 +599,7 @@ static EFI_STATUS generate_hash (char *data, int datasize_in,
/* Validate SectionPtr is within image */
SectionPtr = ImageAddress(data, datasize,
PEHdr_offset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
context->PEHdr->Pe32.FileHeader.SizeOfOptionalHeader +
......@@ -617,7 +627,9 @@ static EFI_STATUS generate_hash (char *data, int datasize_in,
}
/* Already validated above */
Section = ImageAddress(data, datasize, sizeof (UINT32) +
Section = ImageAddress(data, datasize,
PEHdr_offset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
context->PEHdr->Pe32.FileHeader.SizeOfOptionalHeader);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment