readelf: Handle NULL shdr in section_name
Commit Message
In some error cases we want to show the section name but cannot
because the section header is corrupt or NULL. Make sure the
section_name always returns "???" in that case.
* src/readelf.c (section_name): Check for shdr == NULL.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
src/readelf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi,
On Thu, 2023-04-06 at 17:04 +0200, Mark Wielaard wrote:
> In some error cases we want to show the section name but cannot
> because the section header is corrupt or NULL. Make sure the
> section_name always returns "???" in that case.
>
> * src/readelf.c (section_name): Check for shdr == NULL.
Pushed,
Mark
@@ -1606,7 +1606,7 @@ static const char *
section_name (Ebl *ebl, GElf_Shdr *shdr)
{
size_t shstrndx;
- if (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)
+ if (shdr == NULL || elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)
return "???";
return elf_strptr (ebl->elf, shstrndx, shdr->sh_name) ?: "???";
}