diff options
| author | Mark Wielaard <[email protected]> | 2014-11-17 23:15:45 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2014-11-17 23:19:03 +0100 |
| commit | 5c1a45c2d370e7fd1149fa74a9382e202fbfe8fe (patch) | |
| tree | b41fc506962bb78a5b9176600abd968146bc7e2b | |
| parent | 7df0da33f4789e264242a4cb8af30c0aefe6d6b4 (diff) | |
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 <[email protected]>
| -rw-r--r-- | backends/ChangeLog | 4 | ||||
| -rw-r--r-- | backends/ppc64_init.c | 15 | ||||
| -rw-r--r-- | libebl/ChangeLog | 4 | ||||
| -rw-r--r-- | libebl/ebldebugscnp.c | 4 | ||||
| -rw-r--r-- | libelf/ChangeLog | 4 | ||||
| -rw-r--r-- | libelf/elf-knowledge.h | 5 | ||||
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/elfcmp.c | 5 | ||||
| -rw-r--r-- | src/objdump.c | 6 | ||||
| -rw-r--r-- | src/size.c | 7 |
10 files changed, 41 insertions, 19 deletions
diff --git a/backends/ChangeLog b/backends/ChangeLog index 82a2bf15..abd22bf8 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,7 @@ +2014-11-17 Mark Wielaard <[email protected]> + + * ppc64_init.c (ppc64_init): Check section name is not NULL. + 2014-10-06 Mark Wielaard <[email protected]> * libebl_CPU.h (dwarf_peel_type): Removed. diff --git a/backends/ppc64_init.c b/backends/ppc64_init.c index 7ea2b236..56e1828e 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 5ec71016..b6a0e632 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,7 @@ +2014-11-17 Mark Wielaard <[email protected]> + + * ebldebugscnp.c (ebl_debugscn_p): Check name is not NULL. + 2014-06-17 Mark Wielaard <[email protected]> * eblinitreg.c (ebl_func_addr_mask): New function. diff --git a/libebl/ebldebugscnp.c b/libebl/ebldebugscnp.c index f2351e23..01a56754 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 <[email protected]>, 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 633a8923..9ae24a9b 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,7 @@ +2014-11-17 Mark Wielaard <[email protected]> + + * elf-knowledge.h (SECTION_STRIP_P): Check name is not NULL. + 2014-11-16 Mark Wielaard <[email protected]> * elf_getshdrstrndx.c: Check there are section headers before diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h index 99fb9107..24534b38 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 <[email protected]>, 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 96f21fdc..727d1001 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2014-11-17 Mark Wielaard <[email protected]> + * 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 <[email protected]> + * readelf.c (print_debug_frame_section): Warn if ptr_size is not 4 or 8 instead of just calling print_cfa_program. diff --git a/src/elfcmp.c b/src/elfcmp.c index 2d85f0b2..c420019f 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 <[email protected]>, 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 ebad25d5..5376447a 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 <[email protected]>, 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 @@ -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); |
