ImageTool: Fix SymbolsPathLen inconsistencies

This commit is contained in:
Marvin Häuser 2023-03-28 23:35:13 +02:00
parent fbb0bac451
commit ea97361c29
3 changed files with 8 additions and 8 deletions

View File

@ -784,7 +784,7 @@ ScanElf (
mImageInfo.HeaderInfo.IsXip = true;
mImageInfo.SegmentInfo.SegmentAlignment = (uint32_t)mPeAlignment;
mImageInfo.RelocInfo.RelocsStripped = false;
mImageInfo.DebugInfo.SymbolsPathLen = strlen (ElfName) + 1;
mImageInfo.DebugInfo.SymbolsPathLen = strlen (ElfName);
switch (mEhdr->e_machine) {
case EM_386:
@ -805,14 +805,14 @@ ScanElf (
return RETURN_UNSUPPORTED;
}
mImageInfo.DebugInfo.SymbolsPath = calloc (1, mImageInfo.DebugInfo.SymbolsPathLen);
mImageInfo.DebugInfo.SymbolsPath = malloc (mImageInfo.DebugInfo.SymbolsPathLen + 1);
if (mImageInfo.DebugInfo.SymbolsPath == NULL) {
fprintf (stderr, "ImageTool: Could not allocate memory for Debug Data\n");
free (mEhdr);
return RETURN_OUT_OF_RESOURCES;
};
memcpy (mImageInfo.DebugInfo.SymbolsPath, ElfName, mImageInfo.DebugInfo.SymbolsPathLen);
memmove (mImageInfo.DebugInfo.SymbolsPath, ElfName, mImageInfo.DebugInfo.SymbolsPathLen + 1);
if ((strcmp (ModuleType, "BASE") == 0)
|| (strcmp (ModuleType, "SEC") == 0)

View File

@ -180,7 +180,7 @@ EmitPeGetDebugSectionSize (
if (Image->DebugInfo.SymbolsPath != NULL) {
return !BaseOverflowAlignUpU32 (
sizeof (DebugData) + Image->DebugInfo.SymbolsPathLen,
sizeof (DebugData) + Image->DebugInfo.SymbolsPathLen + 1,
Image->SegmentInfo.SegmentAlignment,
DebugSize
);
@ -755,18 +755,18 @@ ToolImageEmitPeDebugTable (
Context->PeHdr->SizeOfImage += ALIGN_VALUE (Context->DebugTableSize, Image->SegmentInfo.SegmentAlignment);
assert (Image->DebugInfo.SymbolsPathLen <= Context->DebugTableSize);
assert (Image->DebugInfo.SymbolsPathLen + 1 <= Context->DebugTableSize);
assert (Context->DebugTableSize <= *BufferSize);
Data = (DebugData *) *Buffer;
Data->Dir.Type = EFI_IMAGE_DEBUG_TYPE_CODEVIEW;
Data->Dir.SizeOfData = sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + Image->DebugInfo.SymbolsPathLen;
Data->Dir.SizeOfData = sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + Image->DebugInfo.SymbolsPathLen + 1;
Data->Dir.RVA = (Context->UnsignedFileSize - ALIGN_VALUE (Context->DebugTableSize, Context->FileAlignment)) + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
Data->Dir.FileOffset = Data->Dir.RVA;
Data->Nb10.Signature = CODEVIEW_SIGNATURE_NB10;
snprintf (Data->Name, Image->DebugInfo.SymbolsPathLen, "%s", Image->DebugInfo.SymbolsPath);
memmove (Data->Name, Image->DebugInfo.SymbolsPath, Image->DebugInfo.SymbolsPathLen + 1);
*BufferSize -= Context->DebugTableSize;
*Buffer += Context->DebugTableSize;

View File

@ -369,7 +369,7 @@ ScanPeGetDebugInfo (
return false;
}
DebugInfo->SymbolsPath = calloc (1, PdbPathSize);
DebugInfo->SymbolsPath = malloc (PdbPathSize);
if (DebugInfo->SymbolsPath == NULL) {
fprintf (stderr, "ImageTool: Could not allocate memory for SymbolsPath\n");
return false;