Closed rvijayc closed 10 months ago
You are correct, this was a mistake on my part.
According to the Elf generic ABI e_shoff of zero means there are no sections.
the following patch is untested, but I will test now and push this soonish.
-- a/src/lib/libdwarf/dwarf_elf_load_headers.c
+++ b/src/lib/libdwarf/dwarf_elf_load_headers.c
@@ -210,8 +210,11 @@ generic_ehdr_from_32(dwarf_elf_object_access_internals_t *ep,
ASNAR(ep->f_copy_word,ehdr->ge_shentsize,e->e_shentsize);
ASNAR(ep->f_copy_word,ehdr->ge_shnum,e->e_shnum);
ASNAR(ep->f_copy_word,ehdr->ge_shstrndx,e->e_shstrndx);
+ if (!ehdr->ge_shoff) {
+ return DW_DLV_NO_ENTRY;
+ }
if (ehdr->ge_shoff < sizeof(dw_elf32_ehdr)) {
- /* zero or offset is inside the header! */
+ /* offset is inside the header! */
I will also patch one of my small test objects to put in a zero e_shoff to ensure the right thing happens.
Thanks for pointing this out. Lets leave this open until it is actually fixed...
Thanks for your response. I assume this will apply to other similar checks as well? For example:
Although, we may never hit this for ELF files with no sections header (we'll bail out earlier on the shoff
check).
What is at line 222 is detecting corrupt dwarf, and is an error.
I created an object with zeroed e_shoff in regressiontests so we have an ongoing test of that specific issue.
Changes pushed to github.
The changes are in today's v0.9.1 release.
Since (I believe) this is fixed, I am closing. I have two test objects now for regression testing, each with e_shoff zero. One Elf32 the other Elf64.
It is quite valid to have an ELF file with program headers only and no section headers (for example, core dumps). But, the following code raises a
DW_DLV_TOO_FEW_SECTIONS
error for such files.https://github.com/davea42/libdwarf-code/blob/c0cfba34ec80996426b5be2523f6447a2c9b7b39/src/lib/libdwarf/dwarf_elf_load_headers.c#L213-L216
Wouldn't it be better to handle this gracefully by returning
DW_DLV_NO_ENTRY
instead ofDW_DLV_ERROR
? I believe this is what the older versions oflibdwarf
used to return when we calleddwarf_elf_init
. I don't believe this should be an error. Please correct me if I missed anything.Appreciate your help! Thank you.