From 08d8fa11878dc2fb68745443a892106379121882 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 17 Jun 2005 13:37:26 +0000 Subject: [PATCH] * elf/external.h (GRP_ENTRY_SIZE): Define. * readelf.c (CHECK_ENTSIZE_VALUES, CHECK_ENTSIZE): Define. (process_section_headers): Use it. (process_relocs): Don't crash if symsec is not SHT_SYMTAB or SHT_DYNSYM. (process_version_sections): Use sizeof (Elf_External_Versym) instead of sh_entsize. --- binutils/ChangeLog | 9 +++++++++ binutils/readelf.c | 31 ++++++++++++++++++++++++++++++- include/ChangeLog | 4 ++++ include/elf/external.h | 5 ++++- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index f47a96f..4319811 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,12 @@ +2005-06-17 Jakub Jelinek + + * readelf.c (CHECK_ENTSIZE_VALUES, CHECK_ENTSIZE): Define. + (process_section_headers): Use it. + (process_relocs): Don't crash if symsec is not SHT_SYMTAB + or SHT_DYNSYM. + (process_version_sections): Use sizeof (Elf_External_Versym) + instead of sh_entsize. + 2005-06-16 Nick Clifton * rename.c (simple_copy): Only define if it is going to be used. diff --git a/binutils/readelf.c b/binutils/readelf.c index 970fbc0..0f945dc 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -3871,6 +3871,22 @@ process_section_headers (FILE *file) break; } +#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ + do \ + { \ + size_t expected_entsize \ + = is_32bit_elf ? size32 : size64; \ + if (section->sh_entsize != expected_entsize) \ + error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \ + i, (unsigned long int) section->sh_entsize, \ + (unsigned long int) expected_entsize); \ + section->sh_entsize = expected_entsize; \ + } \ + while (0) +#define CHECK_ENTSIZE(section, i, type) \ + CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ + sizeof (Elf64_External_##type)) + for (i = 0, section = section_headers; i < elf_header.e_shnum; i++, section++) @@ -3885,6 +3901,7 @@ process_section_headers (FILE *file) continue; } + CHECK_ENTSIZE (section, i, Sym); num_dynamic_syms = section->sh_size / section->sh_entsize; dynamic_symbols = GET_ELF_SYMBOLS (file, section); } @@ -3910,6 +3927,14 @@ process_section_headers (FILE *file) } symtab_shndx_hdr = section; } + else if (section->sh_type == SHT_SYMTAB) + CHECK_ENTSIZE (section, i, Sym); + else if (section->sh_type == SHT_GROUP) + CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); + else if (section->sh_type == SHT_REL) + CHECK_ENTSIZE (section, i, Rel); + else if (section->sh_type == SHT_RELA) + CHECK_ENTSIZE (section, i, Rela); else if ((do_debugging || do_debug_info || do_debug_abbrevs || do_debug_lines || do_debug_pubnames || do_debug_aranges || do_debug_frames || do_debug_macinfo || do_debug_str @@ -4488,6 +4513,10 @@ process_relocs (FILE *file) char *strtab = NULL; symsec = SECTION_HEADER (section->sh_link); + if (symsec->sh_type != SHT_SYMTAB + && symsec->sh_type != SHT_DYNSYM) + continue; + nsyms = symsec->sh_size / symsec->sh_entsize; symtab = GET_ELF_SYMBOLS (file, symsec); @@ -6358,7 +6387,7 @@ process_version_sections (FILE *file) break; link_section = SECTION_HEADER (section->sh_link); - total = section->sh_size / section->sh_entsize; + total = section->sh_size / sizeof (Elf_External_Versym); if (SECTION_HEADER_INDEX (link_section->sh_link) >= elf_header.e_shnum) diff --git a/include/ChangeLog b/include/ChangeLog index 54d7f07..fab3d9c 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2005-06-17 Jakub Jelinek + + * elf/external.h (GRP_ENTRY_SIZE): Define. + 2005-06-08 Zack Weinberg * dis-asm.h (get_arm_regnames): Update prototype. diff --git a/include/elf/external.h b/include/elf/external.h index a7fc767..5985e94 100644 --- a/include/elf/external.h +++ b/include/elf/external.h @@ -1,5 +1,5 @@ /* ELF support for BFD. - Copyright 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2001, 2003 + Copyright 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. Written by Fred Fish @ Cygnus Support, from information published @@ -272,5 +272,8 @@ typedef struct unsigned char a_val[8]; } Elf64_External_Auxv; +/* Size of SHT_GROUP section entry. */ + +#define GRP_ENTRY_SIZE 4 #endif /* _ELF_EXTERNAL_H */ -- 2.7.4