Closed sevaa closed 1 month ago
I like the change more but agree that the motivation remains mysterious, especially without any test case. Is this similar to what readelf
itself is doing in a comparable code path?
There is a similar check in readelf when it retrieves the symbol name for STT_SECTION
type symbols. In readelf's print_symbol()
there is the following:
/* Get the symbol's name. For section symbols without a
specific name use the (already computed) section name. */
if (ELF_ST_TYPE (psym->st_info) == STT_SECTION
&& section_index_real (filedata, psym->st_shndx)
&& psym->st_name == 0)
{
;
}
else
{
bool is_valid;
is_valid = valid_symbol_name (strtab, strtab_size, psym->st_name);
sstr = is_valid ? strtab + psym->st_name : _("<corrupt>");
}
Where section_index_real()
checks, among other things, if st_shndx>0
. So as far as understand, the logic is:
st_shndx
is nonzero, treat it as a section index, retrieve that section's namest_name
<corrupt>
So this tells me that st_shndx
being zero (SHN_UNDEF
) is a condition readelf handles gracefully. So pyelftools shouldn't crash on that either :)
Supersedes #566
Now, I don't know what was the original motivation for that one, but this fix should be equivalent.