From: Michael F. <mf...@mf...> - 2021-05-01 22:00:35
|
Michael Forney <mf...@mf...> wrote: > I agree that the sanity check is good in general, but I have to > wonder if it makes sense to fail if the section type is just not > yet set (SHT_NULL), since that does not necessarily indicate an > application error. Alternatively, an arguably better check is to make sure the Elf_Data has d_type == ELF_T_REL(A). What are your thoughts on that? diff --git a/libelf/gelf_rel.c b/libelf/gelf_rel.c index 60332597..3ff48647 100644 --- a/libelf/gelf_rel.c +++ b/libelf/gelf_rel.c @@ -42,7 +42,6 @@ gelf_getrel(Elf_Data *ed, int ndx, GElf_Rel *dst) Elf *e; size_t msz; Elf_Scn *scn; - uint32_t sh_type; Elf32_Rel *rel32; Elf64_Rel *rel64; struct _Libelf_Data *d; @@ -59,12 +58,7 @@ gelf_getrel(Elf_Data *ed, int ndx, GElf_Rel *dst) ec = e->e_class; assert(ec == ELFCLASS32 || ec == ELFCLASS64); - if (ec == ELFCLASS32) - sh_type = scn->s_shdr.s_shdr32.sh_type; - else - sh_type = scn->s_shdr.s_shdr64.sh_type; - - if (_libelf_xlate_shtype(sh_type) != ELF_T_REL) { + if (d->d_data.d_type != ELF_T_REL) { LIBELF_SET_ERROR(ARGUMENT, 0); return (NULL); } @@ -104,7 +98,6 @@ gelf_update_rel(Elf_Data *ed, int ndx, GElf_Rel *dr) Elf *e; size_t msz; Elf_Scn *scn; - uint32_t sh_type; Elf32_Rel *rel32; Elf64_Rel *rel64; struct _Libelf_Data *d; @@ -121,12 +114,7 @@ gelf_update_rel(Elf_Data *ed, int ndx, GElf_Rel *dr) ec = e->e_class; assert(ec == ELFCLASS32 || ec == ELFCLASS64); - if (ec == ELFCLASS32) - sh_type = scn->s_shdr.s_shdr32.sh_type; - else - sh_type = scn->s_shdr.s_shdr64.sh_type; - - if (_libelf_xlate_shtype(sh_type) != ELF_T_REL) { + if (d->d_data.d_type != ELF_T_REL) { LIBELF_SET_ERROR(ARGUMENT, 0); return (0); } diff --git a/libelf/gelf_rela.c b/libelf/gelf_rela.c index 40462248..71d7e82a 100644 --- a/libelf/gelf_rela.c +++ b/libelf/gelf_rela.c @@ -42,7 +42,6 @@ gelf_getrela(Elf_Data *ed, int ndx, GElf_Rela *dst) Elf *e; size_t msz; Elf_Scn *scn; - uint32_t sh_type; Elf32_Rela *rela32; Elf64_Rela *rela64; struct _Libelf_Data *d; @@ -59,12 +58,7 @@ gelf_getrela(Elf_Data *ed, int ndx, GElf_Rela *dst) ec = e->e_class; assert(ec == ELFCLASS32 || ec == ELFCLASS64); - if (ec == ELFCLASS32) - sh_type = scn->s_shdr.s_shdr32.sh_type; - else - sh_type = scn->s_shdr.s_shdr64.sh_type; - - if (_libelf_xlate_shtype(sh_type) != ELF_T_RELA) { + if (d->d_data.d_type != ELF_T_RELA) { LIBELF_SET_ERROR(ARGUMENT, 0); return (NULL); } @@ -105,7 +99,6 @@ gelf_update_rela(Elf_Data *ed, int ndx, GElf_Rela *dr) Elf *e; size_t msz; Elf_Scn *scn; - uint32_t sh_type; Elf32_Rela *rela32; Elf64_Rela *rela64; struct _Libelf_Data *d; @@ -122,12 +115,7 @@ gelf_update_rela(Elf_Data *ed, int ndx, GElf_Rela *dr) ec = e->e_class; assert(ec == ELFCLASS32 || ec == ELFCLASS64); - if (ec == ELFCLASS32) - sh_type = scn->s_shdr.s_shdr32.sh_type; - else - sh_type = scn->s_shdr.s_shdr64.sh_type; - - if (_libelf_xlate_shtype(sh_type) != ELF_T_RELA) { + if (d->d_data.d_type != ELF_T_RELA) { LIBELF_SET_ERROR(ARGUMENT, 0); return (0); } |