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

* Change the section name parsing to only rstrip zeroes

* Remove accidental <algorithm> include

* Change formatting to match the existing code style
This commit is contained in:
HoundThe 2021-07-20 11:10:50 +02:00 committed by GitHub
parent bde3eb5753
commit 3d506f212f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}