From: Roland McGrath Date: Wed, 30 Jun 2010 07:47:58 +0000 (-0700) Subject: libdwfl: Restore short-circuit on bad reloc type. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c287769d0bf2dedbc94907704add4d9f1926fa1;p=thirdparty%2Felfutils.git libdwfl: Restore short-circuit on bad reloc type. --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 34d7c002b..dcc91503b 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2010-06-30 Roland McGrath + + * relocate.c (relocate_section): Check for bad reloc type before + looking up symndx. + 2010-06-29 Roland McGrath * derelocate.c (check_module): Don't call dwfl_module_getdwarf. diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c index b89de37ef..30b206e3b 100644 --- a/libdwfl/relocate.c +++ b/libdwfl/relocate.c @@ -346,6 +346,26 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, So we just pretend it's OK without further relocation. */ return DWFL_E_NOERROR; + /* These are the types we can relocate. */ + size_t size = 4; + for (const int *tp = reloc_symtab->rel8_types; *tp != 0; ++tp) + if (*tp == rtype) + { + size = 8; + break; + } + if (size == 4) + { + const int *tp = reloc_symtab->rel4_types; + while (*tp != 0 && *tp != rtype) + ++tp; + if (unlikely (*tp == 0)) + return DWFL_E_BADRELTYPE; + } + + if (offset + size > tdata->d_size) + return DWFL_E_BADRELOFF; + /* First, resolve the symbol to an absolute value. */ GElf_Addr value; @@ -378,26 +398,6 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, value = sym.st_value; } - /* These are the types we can relocate. */ - size_t size = 4; - for (const int *tp = reloc_symtab->rel8_types; *tp != 0; ++tp) - if (*tp == rtype) - { - size = 8; - break; - } - if (size == 4) - { - const int *tp = reloc_symtab->rel4_types; - while (*tp != 0 && *tp != rtype) - ++tp; - if (unlikely (*tp == 0)) - return DWFL_E_BADRELTYPE; - } - - if (offset + size > tdata->d_size) - return DWFL_E_BADRELOFF; - BYTE_ORDER_DUMMY (bo, ehdr->e_ident); /* XXX check for overflow? */