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

Change the section name parsing to only remove trailing zeroes #979

Merged
merged 3 commits into from
Jul 20, 2021
Merged
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
19 changes: 12 additions & 7 deletions src/pelib/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,16 +1842,21 @@ int PeLib::ImageLoader::captureSectionName(

// The section name is directly in the section header.
// It has fixed length and must not be necessarily terminated with zero.
// Historically, PELIB copies the name of the section WITHOUT zero chars,
// even if the zero chars are in the middle. Aka ".text\0\0X" results in ".textX"
sectionName.clear();
for(size_t i = 0; i < PELIB_IMAGE_SIZEOF_SHORT_NAME; i++)

// rstrip trailing nulls
const uint8_t* end = Name + PELIB_IMAGE_SIZEOF_SHORT_NAME;
// find the first non-null from end
do
{
if(Name[i])
{
sectionName += Name[i];
}
end--;
} while (end - Name > 0 && *end == 0);

if (end - Name > 0)
{
sectionName.assign(Name, end + 1);
}

return ERROR_NONE;
}

Expand Down