From: Mark Wielaard Date: Mon, 17 Nov 2014 22:15:45 +0000 (+0100) Subject: Check elf_strptr didn't fail getting section name. X-Git-Tag: elfutils-0.161~80 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c1a45c2d370e7fd1149fa74a9382e202fbfe8fe;p=thirdparty%2Felfutils.git Check elf_strptr didn't fail getting section name. Since elf_strptr can fail and return NULL we should always check the result before usage. Debug sections are only handled by section name, so make sure the name actually exists. Signed-off-by: Mark Wielaard --- diff --git a/backends/ChangeLog b/backends/ChangeLog index 82a2bf159..abd22bf88 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,7 @@ +2014-11-17 Mark Wielaard + + * ppc64_init.c (ppc64_init): Check section name is not NULL. + 2014-10-06 Mark Wielaard * libebl_CPU.h (dwarf_peel_type): Removed. diff --git a/backends/ppc64_init.c b/backends/ppc64_init.c index 7ea2b2363..56e1828ef 100644 --- a/backends/ppc64_init.c +++ b/backends/ppc64_init.c @@ -90,13 +90,16 @@ ppc64_init (elf, machine, eh, ehlen) if (opd_shdr != NULL && (opd_shdr->sh_flags & SHF_ALLOC) != 0 && opd_shdr->sh_type == SHT_PROGBITS - && opd_shdr->sh_size > 0 - && strcmp (elf_strptr (elf, ehdr->e_shstrndx, - opd_shdr->sh_name), ".opd") == 0) + && opd_shdr->sh_size > 0) { - eh->fd_addr = opd_shdr->sh_addr; - eh->fd_data = elf_getdata (scn, NULL); - break; + const char *name = elf_strptr (elf, ehdr->e_shstrndx, + opd_shdr->sh_name); + if (name != NULL && strcmp (name, ".opd") == 0) + { + eh->fd_addr = opd_shdr->sh_addr; + eh->fd_data = elf_getdata (scn, NULL); + break; + } } } } diff --git a/libebl/ChangeLog b/libebl/ChangeLog index 5ec710166..b6a0e6323 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,7 @@ +2014-11-17 Mark Wielaard + + * ebldebugscnp.c (ebl_debugscn_p): Check name is not NULL. + 2014-06-17 Mark Wielaard * eblinitreg.c (ebl_func_addr_mask): New function. diff --git a/libebl/ebldebugscnp.c b/libebl/ebldebugscnp.c index f2351e23c..01a567542 100644 --- a/libebl/ebldebugscnp.c +++ b/libebl/ebldebugscnp.c @@ -1,5 +1,5 @@ /* Check section name for being that of a debug informatino section. - Copyright (C) 2002 Red Hat, Inc. + Copyright (C) 2002, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 2002. @@ -40,5 +40,5 @@ ebl_debugscn_p (ebl, name) Ebl *ebl; const char *name; { - return ebl->debugscn_p (name); + return name != NULL && ebl->debugscn_p (name); } diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 633a8923f..9ae24a9be 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2014-11-17 Mark Wielaard + + * elf-knowledge.h (SECTION_STRIP_P): Check name is not NULL. + 2014-11-16 Mark Wielaard * elf_getshdrstrndx.c: Check there are section headers before diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h index 99fb91071..24534b383 100644 --- a/libelf/elf-knowledge.h +++ b/libelf/elf-knowledge.h @@ -1,5 +1,5 @@ /* Accumulation of various pieces of knowledge about ELF. - Copyright (C) 2000-2012 Red Hat, Inc. + Copyright (C) 2000-2012, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 2000. @@ -41,7 +41,8 @@ && (shdr)->sh_type != SHT_NOTE \ && (((shdr)->sh_type) != SHT_PROGBITS \ /* Never remove .gnu.warning.* sections. */ \ - || (strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0 \ + || (name != NULL \ + && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\ /* We remove .comment sections only if explicitly told to do so. */\ && (remove_comment \ || strcmp (name, ".comment") != 0)))) diff --git a/src/ChangeLog b/src/ChangeLog index 96f21fdc3..727d1001a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2014-11-17 Mark Wielaard + + * elfcmp.c (main): Check section names are NULL before use. + * objdump.c (section_match): Likewise. + * size.c (show_sysv): Likewise. + 2014-11-17 Mark Wielaard * readelf.c (print_debug_frame_section): Warn if ptr_size is not 4 diff --git a/src/elfcmp.c b/src/elfcmp.c index 2d85f0b2e..c420019f5 100644 --- a/src/elfcmp.c +++ b/src/elfcmp.c @@ -1,5 +1,5 @@ /* Compare relevant content of two ELF files. - Copyright (C) 2005-2012 Red Hat, Inc. + Copyright (C) 2005-2012, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 2005. @@ -355,7 +355,8 @@ main (int argc, char *argv[]) sym1->st_name); const char *name2 = elf_strptr (elf2, shdr2->sh_link, sym2->st_name); - if (unlikely (strcmp (name1, name2) != 0 + if (unlikely (name1 == NULL || name2 == NULL + || strcmp (name1, name2) != 0 || sym1->st_value != sym2->st_value || (sym1->st_size != sym2->st_size && sym1->st_shndx != SHN_UNDEF) diff --git a/src/objdump.c b/src/objdump.c index ebad25d52..5376447af 100644 --- a/src/objdump.c +++ b/src/objdump.c @@ -1,5 +1,5 @@ /* Print information from ELF file in human-readable form. - Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012 Red Hat, Inc. + Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 2005. @@ -460,13 +460,13 @@ section_match (Elf *elf, uint32_t scnndx, GElf_Shdr *shdr, size_t shstrndx) return true; struct section_list *runp = section_list; + const char *name = elf_strptr (elf, shstrndx, shdr->sh_name); do { if (runp->is_name) { - if (strcmp (runp->name, - elf_strptr (elf, shstrndx, shdr->sh_name)) == 0) + if (name && strcmp (runp->name, name) == 0) return true; } else diff --git a/src/size.c b/src/size.c index 9db55c80d..cb67999b4 100644 --- a/src/size.c +++ b/src/size.c @@ -427,10 +427,9 @@ show_sysv (Elf *elf, const char *prefix, const char *fname, INTERNAL_ERROR (fullname); /* Ignore all sections which are not used at runtime. */ - if ((shdr->sh_flags & SHF_ALLOC) != 0) - maxlen = MAX (maxlen, - (int) strlen (elf_strptr (elf, shstrndx, - shdr->sh_name))); + const char *name = elf_strptr (elf, shstrndx, shdr->sh_name); + if (name != NULL && (shdr->sh_flags & SHF_ALLOC) != 0) + maxlen = MAX (maxlen, (int) strlen (name)); } fputs_unlocked (fname, stdout);