* [COMMITTED] Check elf_strptr didn't fail getting section name.
@ 2014-11-17 22:20 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2014-11-17 22:20 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 7087 bytes --]
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 <mjw@redhat.com>
---
backends/ChangeLog | 4 ++++
backends/ppc64_init.c | 15 +++++++++------
libebl/ChangeLog | 4 ++++
libebl/ebldebugscnp.c | 4 ++--
libelf/ChangeLog | 4 ++++
libelf/elf-knowledge.h | 5 +++--
src/ChangeLog | 6 ++++++
src/elfcmp.c | 5 +++--
src/objdump.c | 6 +++---
src/size.c | 7 +++----
10 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/backends/ChangeLog b/backends/ChangeLog
index 82a2bf1..abd22bf 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-17 Mark Wielaard <mjw@redhat.com>
+
+ * ppc64_init.c (ppc64_init): Check section name is not NULL.
+
2014-10-06 Mark Wielaard <mjw@redhat.com>
* libebl_CPU.h (dwarf_peel_type): Removed.
diff --git a/backends/ppc64_init.c b/backends/ppc64_init.c
index 7ea2b23..56e1828 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 5ec7101..b6a0e63 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-17 Mark Wielaard <mjw@redhat.com>
+
+ * ebldebugscnp.c (ebl_debugscn_p): Check name is not NULL.
+
2014-06-17 Mark Wielaard <mjw@redhat.com>
* eblinitreg.c (ebl_func_addr_mask): New function.
diff --git a/libebl/ebldebugscnp.c b/libebl/ebldebugscnp.c
index f2351e2..01a5675 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 <drepper@redhat.com>, 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 633a892..9ae24a9 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-17 Mark Wielaard <mjw@redhat.com>
+
+ * elf-knowledge.h (SECTION_STRIP_P): Check name is not NULL.
+
2014-11-16 Mark Wielaard <mjw@redhat.com>
* elf_getshdrstrndx.c: Check there are section headers before
diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h
index 99fb910..24534b3 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 <drepper@redhat.com>, 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 96f21fd..727d100 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
2014-11-17 Mark Wielaard <mjw@redhat.com>
+ * 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 <mjw@redhat.com>
+
* 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 2d85f0b..c420019 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 <drepper@redhat.com>, 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 ebad25d..5376447 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 <drepper@redhat.com>, 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 9db55c8..cb67999 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);
--
1.8.3.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-11-17 22:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-17 22:20 [COMMITTED] Check elf_strptr didn't fail getting section name Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).