2012-02-23 12:24:19 +00:00
--- elfutils/libdwfl/ChangeLog
+++ elfutils/libdwfl/ChangeLog
2012-06-22 12:58:36 +00:00
@@ -48,6 +48,11 @@
2012-02-23 12:24:19 +00:00
* dwfl_module_getdwarf.c (open_elf): Clear errno before CBFAIL.
Reported by Kurt Roeckx <kurt@roeckx.be>.
+2011-03-23 Petr Machata <pmachata@redhat.com>
+
+ * relocate.c (relocate_section): Use gelf_fsize instead of relying
+ on shdr->sh_entsize.
+
2011-02-11 Roland McGrath <roland@redhat.com>
* linux-kernel-modules.c (try_kernel_name): Try .gz, .bz2, .xz
--- elfutils/libdwfl/relocate.c
+++ elfutils/libdwfl/relocate.c
@@ -1,5 +1,5 @@
/* Relocate debug information.
- Copyright (C) 2005-2010 Red Hat, Inc.
+ Copyright (C) 2005-2011 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2012-02-23 12:24:19 +00:00
2012-06-22 12:58:36 +00:00
This file is free software; you can redistribute it and/or modify
@@ -457,7 +457,10 @@ relocate_section (Dwfl_Module *mod, Elf
2012-02-23 12:24:19 +00:00
}
}
- size_t nrels = shdr->sh_size / shdr->sh_entsize;
+ size_t sh_entsize
+ = gelf_fsize (relocated, shdr->sh_type == SHT_REL ? ELF_T_REL : ELF_T_RELA,
+ 1, EV_CURRENT);
+ size_t nrels = shdr->sh_size / sh_entsize;
size_t complete = 0;
if (shdr->sh_type == SHT_REL)
for (size_t relidx = 0; !result && relidx < nrels; ++relidx)
2012-06-22 12:58:36 +00:00
@@ -559,7 +562,7 @@ relocate_section (Dwfl_Module *mod, Elf
2012-02-23 12:24:19 +00:00
nrels = next;
}
- shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize;
+ shdr->sh_size = reldata->d_size = nrels * sh_entsize;
gelf_update_shdr (scn, shdr);
}
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/ChangeLog
+++ elfutils/libelf/ChangeLog
2012-06-22 12:58:36 +00:00
@@ -676,10 +676,53 @@
2009-01-24 01:16:36 +00:00
If section content hasn't been read yet, do it before looking for the
block size. If no section data present, infer size of section header.
+2005-05-14 Jakub Jelinek <jakub@redhat.com>
+
+ * libelfP.h (INVALID_NDX): Define.
+ * gelf_getdyn.c (gelf_getdyn): Use it. Remove ndx < 0 test if any.
+ * gelf_getlib.c (gelf_getlib): Likewise.
+ * gelf_getmove.c (gelf_getmove): Likewise.
+ * gelf_getrel.c (gelf_getrel): Likewise.
+ * gelf_getrela.c (gelf_getrela): Likewise.
+ * gelf_getsym.c (gelf_getsym): Likewise.
+ * gelf_getsyminfo.c (gelf_getsyminfo): Likewise.
+ * gelf_getsymshndx.c (gelf_getsymshndx): Likewise.
+ * gelf_getversym.c (gelf_getversym): Likewise.
+ * gelf_update_dyn.c (gelf_update_dyn): Likewise.
+ * gelf_update_lib.c (gelf_update_lib): Likewise.
+ * gelf_update_move.c (gelf_update_move): Likewise.
+ * gelf_update_rel.c (gelf_update_rel): Likewise.
+ * gelf_update_rela.c (gelf_update_rela): Likewise.
+ * gelf_update_sym.c (gelf_update_sym): Likewise.
+ * gelf_update_syminfo.c (gelf_update_syminfo): Likewise.
+ * gelf_update_symshndx.c (gelf_update_symshndx): Likewise.
+ * gelf_update_versym.c (gelf_update_versym): Likewise.
+ * elf_newscn.c (elf_newscn): Check for overflow.
+ * elf32_updatefile.c (__elfw2(LIBELFBITS,updatemmap)): Likewise.
+ (__elfw2(LIBELFBITS,updatefile)): Likewise.
+ * elf_begin.c (file_read_elf): Likewise.
+ * elf32_newphdr.c (elfw2(LIBELFBITS,newphdr)): Likewise.
+ * elf_getarsym.c (elf_getarsym): Likewise.
+ * elf32_getshdr.c (elfw2(LIBELFBITS,getshdr)): Likewise.
2005-05-11 Ulrich Drepper <drepper@redhat.com>
* elf.h: Update again.
2010-04-21 23:56:02 +00:00
+2005-05-17 Jakub Jelinek <jakub@redhat.com>
+
+ * elf32_getphdr.c (elfw2(LIBELFBITS,getphdr)): Check if program header
+ table fits into object's bounds.
+ * elf_getshstrndx.c (elf_getshstrndx): Add elf->start_offset to
+ elf->map_address. Check if first section header fits into object's
+ bounds.
+ * elf32_getshdr.c (elfw2(LIBELFBITS,getshdr)):
+ Check if section header table fits into object's bounds.
+ * elf_begin.c (get_shnum): Ensure section headers fits into
+ object's bounds.
+ (file_read_elf): Make sure scncnt is small enough to allocate both
+ ElfXX_Shdr and Elf_Scn array. Make sure section and program header
+ tables fit into object's bounds. Avoid memory leak on failure.
+
2005-05-09 Ulrich Drepper <drepper@redhat.com>
* elf.h: Update from glibc.
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf32_getphdr.c
+++ elfutils/libelf/elf32_getphdr.c
2012-06-22 12:58:36 +00:00
@@ -93,6 +93,16 @@ __elfw2(LIBELFBITS,getphdr_wrlock) (elf)
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (elf->map_address != NULL)
{
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
+ if (unlikely (ehdr->e_phoff >= elf->maximum_size)
2009-09-21 17:44:00 +00:00
+ || unlikely (elf->maximum_size - ehdr->e_phoff < size))
2008-08-27 08:19:16 +00:00
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_PHDR);
+ goto out;
+ }
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
/* All the data is already mapped. Use it. */
void *file_phdr = ((char *) elf->map_address
+ elf->start_offset + ehdr->e_phoff);
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf32_getshdr.c
+++ elfutils/libelf/elf32_getshdr.c
2008-08-27 08:19:16 +00:00
@@ -1,5 +1,5 @@
/* Return section header.
2009-07-29 02:19:14 +00:00
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2007, 2009 Red Hat, Inc.
+ Copyright (C) 1998-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2008-08-27 08:19:16 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 1998.
2012-06-22 12:58:36 +00:00
@@ -60,7 +60,8 @@ load_shdr_wrlock (Elf_Scn *scn)
2008-08-27 08:19:16 +00:00
goto out;
size_t shnum;
2009-07-29 02:19:14 +00:00
- if (__elf_getshdrnum_rdlock (elf, &shnum) != 0)
+ if (__elf_getshdrnum_rdlock (elf, &shnum) != 0
2008-08-27 08:19:16 +00:00
+ || shnum > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Shdr)))
goto out;
size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr));
2012-06-22 12:58:36 +00:00
@@ -77,6 +78,16 @@ load_shdr_wrlock (Elf_Scn *scn)
2008-08-27 08:19:16 +00:00
if (elf->map_address != NULL)
{
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
+ if (unlikely (ehdr->e_shoff >= elf->maximum_size)
2009-09-21 17:44:00 +00:00
+ || unlikely (elf->maximum_size - ehdr->e_shoff < size))
2008-08-27 08:19:16 +00:00
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ goto free_and_out;
+ }
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
ElfW2(LIBELFBITS,Shdr) *notcvt;
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
/* All the data is already mapped. If we could use it
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf32_newphdr.c
+++ elfutils/libelf/elf32_newphdr.c
2012-06-22 12:58:36 +00:00
@@ -114,6 +114,12 @@ elfw2(LIBELFBITS,newphdr) (elf, count)
2010-01-15 03:59:06 +00:00
|| count == PN_XNUM
2008-08-27 08:19:16 +00:00
|| elf->state.ELFW(elf,LIBELFBITS).phdr == NULL)
{
+ if (unlikely (count > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Phdr))))
+ {
+ result = NULL;
+ goto out;
+ }
+
/* Allocate a new program header with the appropriate number of
elements. */
result = (ElfW2(LIBELFBITS,Phdr) *)
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf32_updatefile.c
+++ elfutils/libelf/elf32_updatefile.c
2012-06-22 12:58:36 +00:00
@@ -202,6 +202,9 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf
2008-08-27 08:19:16 +00:00
/* Write all the sections. Well, only those which are modified. */
if (shnum > 0)
{
+ if (unlikely (shnum > SIZE_MAX / sizeof (Elf_Scn *)))
+ return 1;
+
Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns;
Elf_Scn **scns = (Elf_Scn **) alloca (shnum * sizeof (Elf_Scn *));
char *const shdr_start = ((char *) elf->map_address + elf->start_offset
2012-06-22 12:58:36 +00:00
@@ -624,6 +627,10 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf
2008-08-27 08:19:16 +00:00
/* Write all the sections. Well, only those which are modified. */
if (shnum > 0)
{
+ if (unlikely (shnum > SIZE_MAX / (sizeof (Elf_Scn *)
+ + sizeof (ElfW2(LIBELFBITS,Shdr)))))
+ return 1;
+
off_t shdr_offset = elf->start_offset + ehdr->e_shoff;
#if EV_NUM != 2
xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR];
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf_begin.c
+++ elfutils/libelf/elf_begin.c
2012-06-22 12:58:36 +00:00
@@ -144,7 +144,8 @@ get_shnum (void *map_address, unsigned c
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (unlikely (result == 0) && ehdr.e32->e_shoff != 0)
{
- if (ehdr.e32->e_shoff + sizeof (Elf32_Shdr) > maxsize)
+ if (unlikely (ehdr.e32->e_shoff >= maxsize)
2009-09-21 17:44:00 +00:00
+ || unlikely (maxsize - ehdr.e32->e_shoff < sizeof (Elf32_Shdr)))
2008-08-27 08:19:16 +00:00
/* Cannot read the first section header. */
return 0;
2008-01-22 01:09:23 +00:00
2012-06-22 12:58:36 +00:00
@@ -192,7 +193,8 @@ get_shnum (void *map_address, unsigned c
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (unlikely (result == 0) && ehdr.e64->e_shoff != 0)
2008-01-22 01:09:23 +00:00
{
2008-08-27 08:19:16 +00:00
- if (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize)
+ if (unlikely (ehdr.e64->e_shoff >= maxsize)
+ || unlikely (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize))
/* Cannot read the first section header. */
return 0;
2008-01-22 01:09:23 +00:00
2012-06-22 12:58:36 +00:00
@@ -264,6 +266,15 @@ file_read_elf (int fildes, void *map_add
2008-08-27 08:19:16 +00:00
/* Could not determine the number of sections. */
return NULL;
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
+ /* Check for too many sections. */
+ if (e_ident[EI_CLASS] == ELFCLASS32)
+ {
+ if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf32_Shdr)))
+ return NULL;
+ }
+ else if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf64_Shdr)))
+ return NULL;
2008-01-22 01:09:23 +00:00
+
2010-01-15 03:59:06 +00:00
/* We can now allocate the memory. Even if there are no section headers,
we allocate space for a zeroth section in case we need it later. */
const size_t scnmax = (scncnt ?: (cmd == ELF_C_RDWR || cmd == ELF_C_RDWR_MMAP)
2012-06-22 12:58:36 +00:00
@@ -303,6 +314,16 @@ file_read_elf (int fildes, void *map_add
2008-01-22 01:09:23 +00:00
{
2008-08-27 08:19:16 +00:00
/* We can use the mmapped memory. */
elf->state.elf32.ehdr = ehdr;
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
+ if (unlikely (ehdr->e_shoff >= maxsize)
2009-09-21 17:44:00 +00:00
+ || unlikely (maxsize - ehdr->e_shoff
+ < scncnt * sizeof (Elf32_Shdr)))
2008-08-27 08:19:16 +00:00
+ {
+ free_and_out:
+ free (elf);
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ return NULL;
+ }
elf->state.elf32.shdr
= (Elf32_Shdr *) ((char *) ehdr + ehdr->e_shoff);
2008-01-22 01:09:23 +00:00
2012-06-22 12:58:36 +00:00
@@ -389,6 +410,11 @@ file_read_elf (int fildes, void *map_add
2008-08-27 08:19:16 +00:00
{
/* We can use the mmapped memory. */
elf->state.elf64.ehdr = ehdr;
+
+ if (unlikely (ehdr->e_shoff >= maxsize)
+ || unlikely (ehdr->e_shoff
+ + scncnt * sizeof (Elf32_Shdr) > maxsize))
+ goto free_and_out;
elf->state.elf64.shdr
= (Elf64_Shdr *) ((char *) ehdr + ehdr->e_shoff);
2008-01-22 01:09:23 +00:00
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf_getarsym.c
+++ elfutils/libelf/elf_getarsym.c
2012-06-22 12:58:36 +00:00
@@ -158,6 +158,9 @@ elf_getarsym (elf, ptr)
2008-08-27 08:19:16 +00:00
size_t index_size = atol (tmpbuf);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (SARMAG + sizeof (struct ar_hdr) + index_size > elf->maximum_size
+#if SIZE_MAX <= 4294967295U
+ || n >= SIZE_MAX / sizeof (Elf_Arsym)
+#endif
|| n * sizeof (uint32_t) > index_size)
{
/* This index table cannot be right since it does not fit into
2009-07-29 02:19:14 +00:00
--- elfutils/libelf/elf_getshdrstrndx.c
+++ elfutils/libelf/elf_getshdrstrndx.c
2012-06-22 12:58:36 +00:00
@@ -104,10 +104,25 @@ elf_getshdrstrndx (elf, dst)
2008-08-27 08:19:16 +00:00
if (elf->map_address != NULL
&& elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA
&& (ALLOW_UNALIGNED
- || (((size_t) ((char *) elf->map_address + offset))
+ || (((size_t) ((char *) elf->map_address
+ + elf->start_offset + offset))
& (__alignof__ (Elf32_Shdr) - 1)) == 0))
2009-09-21 17:44:00 +00:00
- /* We can directly access the memory. */
- num = ((Elf32_Shdr *) (elf->map_address + offset))->sh_link;
2008-08-27 08:19:16 +00:00
+ {
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
2009-09-21 17:44:00 +00:00
+ if (unlikely (elf->maximum_size - offset
+ < sizeof (Elf32_Shdr)))
2008-08-27 08:19:16 +00:00
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ result = -1;
+ goto out;
+ }
+
2009-09-21 17:44:00 +00:00
+ /* We can directly access the memory. */
2008-08-27 08:19:16 +00:00
+ num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset
+ + offset))->sh_link;
+ }
else
{
/* We avoid reading in all the section headers. Just read
2012-06-22 12:58:36 +00:00
@@ -142,10 +157,25 @@ elf_getshdrstrndx (elf, dst)
2008-08-27 08:19:16 +00:00
if (elf->map_address != NULL
&& elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA
&& (ALLOW_UNALIGNED
- || (((size_t) ((char *) elf->map_address + offset))
+ || (((size_t) ((char *) elf->map_address
+ + elf->start_offset + offset))
& (__alignof__ (Elf64_Shdr) - 1)) == 0))
2009-09-21 17:44:00 +00:00
- /* We can directly access the memory. */
- num = ((Elf64_Shdr *) (elf->map_address + offset))->sh_link;
2008-08-27 08:19:16 +00:00
+ {
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
2009-09-21 17:44:00 +00:00
+ if (unlikely (elf->maximum_size - offset
+ < sizeof (Elf64_Shdr)))
2008-08-27 08:19:16 +00:00
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ result = -1;
+ goto out;
+ }
+
2009-09-21 17:44:00 +00:00
+ /* We can directly access the memory. */
+ num = ((Elf64_Shdr *) (elf->map_address + elf->start_offset
+ + offset))->sh_link;
2008-08-27 08:19:16 +00:00
+ }
else
{
/* We avoid reading in all the section headers. Just read
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/elf_newscn.c
+++ elfutils/libelf/elf_newscn.c
2012-06-22 12:58:36 +00:00
@@ -83,10 +83,18 @@ elf_newscn (elf)
2008-08-27 08:19:16 +00:00
else
2008-01-22 01:09:23 +00:00
{
2008-08-27 08:19:16 +00:00
/* We must allocate a new element. */
- Elf_ScnList *newp;
+ Elf_ScnList *newp = NULL;
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
assert (elf->state.elf.scnincr > 0);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
+ if (
+#if SIZE_MAX <= 4294967295U
+ likely (elf->state.elf.scnincr
+ < SIZE_MAX / 2 / sizeof (Elf_Scn) - sizeof (Elf_ScnList))
+#else
+ 1
+#endif
+ )
newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList)
+ ((elf->state.elf.scnincr *= 2)
* sizeof (Elf_Scn)), 1);
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getdyn.c
+++ elfutils/libelf/gelf_getdyn.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get information from dynamic table at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -72,7 +72,7 @@ gelf_getdyn (data, ndx, dst)
2008-08-27 08:19:16 +00:00
table entries has to be adopted. The user better has provided
a buffer where we can store the information. While copying the
data we are converting the format. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Dyn, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -93,7 +93,7 @@ gelf_getdyn (data, ndx, dst)
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Dyn, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getlib.c
+++ elfutils/libelf/gelf_getlib.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get library from table at the given index.
- Copyright (C) 2004 Red Hat, Inc.
+ Copyright (C) 2004-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2004.
2012-06-22 12:58:36 +00:00
@@ -65,7 +65,7 @@ gelf_getlib (data, ndx, dst)
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
GElf_Lib *result = NULL;
- if (unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Lib, data))
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
else
2008-01-22 01:09:23 +00:00
{
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getmove.c
+++ elfutils/libelf/gelf_getmove.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get move structure at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -62,7 +62,7 @@ gelf_getmove (data, ndx, dst)
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Move, data))
2008-01-22 01:09:23 +00:00
{
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getrela.c
+++ elfutils/libelf/gelf_getrela.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get RELA relocation information at given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -50,12 +50,6 @@ gelf_getrela (data, ndx, dst)
2008-08-27 08:19:16 +00:00
if (data_scn == NULL)
return NULL;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return NULL;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_RELA))
{
__libelf_seterrno (ELF_E_INVALID_HANDLE);
2012-06-22 12:58:36 +00:00
@@ -72,7 +66,7 @@ gelf_getrela (data, ndx, dst)
2008-08-27 08:19:16 +00:00
if (scn->elf->class == ELFCLASS32)
{
/* We have to convert the data. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Rela, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
result = NULL;
2012-06-22 12:58:36 +00:00
@@ -93,7 +87,7 @@ gelf_getrela (data, ndx, dst)
2008-08-27 08:19:16 +00:00
{
/* Simply copy the data after we made sure we are actually getting
correct data. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
result = NULL;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getrel.c
+++ elfutils/libelf/gelf_getrel.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get REL relocation information at given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -50,12 +50,6 @@ gelf_getrel (data, ndx, dst)
2008-08-27 08:19:16 +00:00
if (data_scn == NULL)
return NULL;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return NULL;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_REL))
{
__libelf_seterrno (ELF_E_INVALID_HANDLE);
2012-06-22 12:58:36 +00:00
@@ -72,7 +66,7 @@ gelf_getrel (data, ndx, dst)
2008-08-27 08:19:16 +00:00
if (scn->elf->class == ELFCLASS32)
{
/* We have to convert the data. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Rel, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
result = NULL;
2012-06-22 12:58:36 +00:00
@@ -92,7 +86,7 @@ gelf_getrel (data, ndx, dst)
2008-08-27 08:19:16 +00:00
{
/* Simply copy the data after we made sure we are actually getting
correct data. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
result = NULL;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getsym.c
+++ elfutils/libelf/gelf_getsym.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get symbol information from symbol table at the given index.
- Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 1999-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 1999.
2012-06-22 12:58:36 +00:00
@@ -69,7 +69,7 @@ gelf_getsym (data, ndx, dst)
2008-08-27 08:19:16 +00:00
table entries has to be adopted. The user better has provided
a buffer where we can store the information. While copying the
data we are converting the format. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Sym, data))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -98,7 +98,7 @@ gelf_getsym (data, ndx, dst)
2007-04-19 16:28:12 +00:00
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Sym, data))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getsyminfo.c
+++ elfutils/libelf/gelf_getsyminfo.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get additional symbol information from symbol table at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -63,7 +63,7 @@ gelf_getsyminfo (data, ndx, dst)
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Syminfo, data))
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getsymshndx.c
+++ elfutils/libelf/gelf_getsymshndx.c
2009-09-21 17:44:00 +00:00
@@ -1,6 +1,6 @@
/* Get symbol information and separate section index from symbol table
at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -69,7 +69,7 @@ gelf_getsymshndx (symdata, shndxdata, nd
2008-08-27 08:19:16 +00:00
section index table. */
if (likely (shndxdata_scn != NULL))
{
- if (unlikely ((ndx + 1) * sizeof (Elf32_Word) > shndxdata_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Word, &shndxdata_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -89,7 +89,7 @@ gelf_getsymshndx (symdata, shndxdata, nd
2008-08-27 08:19:16 +00:00
table entries has to be adopted. The user better has provided
a buffer where we can store the information. While copying the
data we are converting the format. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Sym, symdata))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -118,7 +118,7 @@ gelf_getsymshndx (symdata, shndxdata, nd
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Sym, symdata))
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_getversym.c
+++ elfutils/libelf/gelf_getversym.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Get symbol version information at the given index.
- Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 1999-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 1999.
2012-06-22 12:58:36 +00:00
@@ -71,7 +71,7 @@ gelf_getversym (data, ndx, dst)
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* The data is already in the correct form. Just make sure the
index is OK. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Versym, data))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
result = NULL;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_dyn.c
+++ elfutils/libelf/gelf_update_dyn.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update information in dynamic table at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -50,12 +50,6 @@ gelf_update_dyn (data, ndx, src)
2008-08-27 08:19:16 +00:00
if (data == NULL)
return 0;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_DYN))
{
/* The type of the data better should match. */
2012-06-22 12:58:36 +00:00
@@ -81,7 +75,7 @@ gelf_update_dyn (data, ndx, src)
2007-04-19 16:28:12 +00:00
}
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Dyn, &data_scn->d))
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -95,7 +89,7 @@ gelf_update_dyn (data, ndx, src)
2008-08-27 08:19:16 +00:00
else
{
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Dyn, &data_scn->d))
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_lib.c
+++ elfutils/libelf/gelf_update_lib.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update library in table at the given index.
- Copyright (C) 2004 Red Hat, Inc.
+ Copyright (C) 2004-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2004.
2012-06-22 12:58:36 +00:00
@@ -47,12 +47,6 @@ gelf_update_lib (data, ndx, src)
2008-08-27 08:19:16 +00:00
if (data == NULL)
return 0;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
if (unlikely (data_scn->d.d_type != ELF_T_LIB))
{
2012-06-22 12:58:36 +00:00
@@ -66,7 +60,7 @@ gelf_update_lib (data, ndx, src)
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
int result = 0;
- if (unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Lib, &data_scn->d))
2008-08-27 08:19:16 +00:00
__libelf_seterrno (ELF_E_INVALID_INDEX);
else
{
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_move.c
+++ elfutils/libelf/gelf_update_move.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update move structure at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -54,8 +54,7 @@ gelf_update_move (data, ndx, src)
2008-08-27 08:19:16 +00:00
assert (sizeof (GElf_Move) == sizeof (Elf64_Move));
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely (ndx < 0)
2009-09-21 17:44:00 +00:00
- || unlikely ((ndx + 1) * sizeof (GElf_Move) > data_scn->d.d_size))
+ if (INVALID_NDX (ndx, GElf_Move, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
2009-09-21 17:44:00 +00:00
return 0;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_rela.c
+++ elfutils/libelf/gelf_update_rela.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update RELA relocation information at given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -47,12 +47,6 @@ gelf_update_rela (Elf_Data *dst, int ndx
2008-08-27 08:19:16 +00:00
if (dst == NULL)
return 0;
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_RELA))
{
/* The type of the data better should match. */
2012-06-22 12:58:36 +00:00
@@ -80,7 +74,7 @@ gelf_update_rela (Elf_Data *dst, int ndx
2008-08-27 08:19:16 +00:00
}
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Rela, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -96,7 +90,7 @@ gelf_update_rela (Elf_Data *dst, int ndx
2008-08-27 08:19:16 +00:00
else
{
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_rel.c
+++ elfutils/libelf/gelf_update_rel.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update REL relocation information at given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -47,12 +47,6 @@ gelf_update_rel (Elf_Data *dst, int ndx,
2008-08-27 08:19:16 +00:00
if (dst == NULL)
return 0;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_REL))
{
/* The type of the data better should match. */
2012-06-22 12:58:36 +00:00
@@ -78,7 +72,7 @@ gelf_update_rel (Elf_Data *dst, int ndx,
2008-08-27 08:19:16 +00:00
}
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Rel, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -93,7 +87,7 @@ gelf_update_rel (Elf_Data *dst, int ndx,
2008-08-27 08:19:16 +00:00
else
{
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_sym.c
+++ elfutils/libelf/gelf_update_sym.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update symbol information in symbol table at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -51,12 +51,6 @@ gelf_update_sym (data, ndx, src)
2008-08-27 08:19:16 +00:00
if (data == NULL)
return 0;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_SYM))
{
/* The type of the data better should match. */
2012-06-22 12:58:36 +00:00
@@ -81,7 +75,7 @@ gelf_update_sym (data, ndx, src)
2008-08-27 08:19:16 +00:00
}
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Sym, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -104,7 +98,7 @@ gelf_update_sym (data, ndx, src)
2008-08-27 08:19:16 +00:00
else
{
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Sym, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_syminfo.c
+++ elfutils/libelf/gelf_update_syminfo.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update additional symbol information in symbol table at the given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -51,12 +51,6 @@ gelf_update_syminfo (data, ndx, src)
2008-08-27 08:19:16 +00:00
if (data == NULL)
return 0;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
if (unlikely (data_scn->d.d_type != ELF_T_SYMINFO))
{
/* The type of the data better should match. */
2012-06-22 12:58:36 +00:00
@@ -72,7 +66,7 @@ gelf_update_syminfo (data, ndx, src)
2008-08-27 08:19:16 +00:00
rwlock_wrlock (scn->elf->lock);
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, GElf_Syminfo, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_symshndx.c
+++ elfutils/libelf/gelf_update_symshndx.c
2009-09-21 17:44:00 +00:00
@@ -1,6 +1,6 @@
/* Update symbol information and section index in symbol table at the
given index.
- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2000-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
2012-06-22 12:58:36 +00:00
@@ -56,12 +56,6 @@ gelf_update_symshndx (symdata, shndxdata
2008-08-27 08:19:16 +00:00
if (symdata == NULL)
return 0;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (unlikely (ndx < 0))
- {
- __libelf_seterrno (ELF_E_INVALID_INDEX);
- return 0;
- }
-
if (unlikely (symdata_scn->d.d_type != ELF_T_SYM))
{
/* The type of the data better should match. */
2012-06-22 12:58:36 +00:00
@@ -107,7 +101,7 @@ gelf_update_symshndx (symdata, shndxdata
2008-08-27 08:19:16 +00:00
}
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf32_Sym, &symdata_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2012-06-22 12:58:36 +00:00
@@ -130,7 +124,7 @@ gelf_update_symshndx (symdata, shndxdata
2008-08-27 08:19:16 +00:00
else
{
/* Check whether we have to resize the data buffer. */
- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size))
2009-09-21 17:44:00 +00:00
+ if (INVALID_NDX (ndx, Elf64_Sym, &symdata_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/gelf_update_versym.c
+++ elfutils/libelf/gelf_update_versym.c
2009-09-21 17:44:00 +00:00
@@ -1,5 +1,5 @@
/* Update symbol version information.
- Copyright (C) 2001, 2002 Red Hat, Inc.
+ Copyright (C) 2001-2009 Red Hat, Inc.
2012-06-22 12:58:36 +00:00
This file is part of elfutils.
2009-09-21 17:44:00 +00:00
Written by Ulrich Drepper <drepper@redhat.com>, 2001.
2012-06-22 12:58:36 +00:00
@@ -54,8 +54,7 @@ gelf_update_versym (data, ndx, src)
2008-08-27 08:19:16 +00:00
assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Check whether we have to resize the data buffer. */
- if (unlikely (ndx < 0)
2009-09-21 17:44:00 +00:00
- || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data_scn->d.d_size))
+ if (INVALID_NDX (ndx, GElf_Versym, &data_scn->d))
2008-08-27 08:19:16 +00:00
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
2009-09-21 17:44:00 +00:00
return 0;
2009-01-24 01:16:36 +00:00
--- elfutils/libelf/libelfP.h
+++ elfutils/libelf/libelfP.h
2012-06-22 12:58:36 +00:00
@@ -587,4 +587,8 @@ extern uint32_t __libelf_crc32 (uint32_t
2008-08-27 08:19:16 +00:00
/* Align offset to 4 bytes as needed for note name and descriptor data. */
#define NOTE_ALIGN(n) (((n) + 3) & -4U)
2005-08-24 22:10:14 +00:00
2009-09-21 17:44:00 +00:00
+/* Convenience macro. */
+#define INVALID_NDX(ndx, type, data) \
+ unlikely ((data)->d_size / sizeof (type) <= (unsigned int) (ndx))
2008-08-27 08:19:16 +00:00
+
#endif /* libelfP.h */
2009-01-24 01:16:36 +00:00
--- elfutils/src/ChangeLog
+++ elfutils/src/ChangeLog
2012-06-22 12:58:36 +00:00
@@ -257,6 +257,12 @@
2012-02-23 12:24:19 +00:00
* readelf.c (dwarf_attr_string): Grok DW_AT_GNU_odr_signature.
+2011-03-23 Petr Machata <pmachata@redhat.com>
+
+ * readelf.c (handle_dynamic, handle_relocs_rel)
+ (handle_relocs_rela, handle_versym, print_liblist):
+ Use gelf_fsize instead of relying on shdr->sh_entsize.
+
2011-02-11 Roland McGrath <roland@redhat.com>
* elfcmp.c (verbose): New variable.
2012-06-22 12:58:36 +00:00
@@ -1969,6 +1975,16 @@
2009-01-24 01:16:36 +00:00
object symbols or symbols with unknown type.
(check_rel): Likewise.
+2005-06-09 Roland McGrath <roland@redhat.com>
+
+ * readelf.c (handle_dynamic, handle_symtab): Check for bogus sh_link.
+ (handle_verneed, handle_verdef, handle_versym, handle_hash): Likewise.
+ (handle_scngrp): Check for bogus sh_info.
+
+ * strip.c (handle_elf): Check for bogus values in sh_link, sh_info,
+ st_shndx, e_shstrndx, and SHT_GROUP or SHT_SYMTAB_SHNDX data.
+ Don't use assert on input values, instead bail with "illformed" error.
+
2005-06-08 Roland McGrath <roland@redhat.com>
* readelf.c (print_ops): Add consts.
2012-06-22 12:58:36 +00:00
@@ -2014,6 +2030,19 @@
2009-01-24 01:16:36 +00:00
* readelf.c (dwarf_tag_string): Add new tags.
+2005-05-17 Jakub Jelinek <jakub@redhat.com>
+
+ * elflint.c (check_hash): Don't check entries beyond end of section.
+ (check_note): Don't crash if gelf_rawchunk fails.
+ (section_name): Return <invalid> if gelf_getshdr returns NULL.
+
+2005-05-14 Jakub Jelinek <jakub@redhat.com>
+
+ * elflint.c (section_name): Return "<invalid>" instead of
+ crashing on invalid section name.
+ (check_symtab, is_rel_dyn, check_rela, check_rel, check_dynamic,
+ check_symtab_shndx, check_hash, check_versym): Robustify.
+
2005-05-08 Roland McGrath <roland@redhat.com>
* strip.c (handle_elf): Don't translate hash and versym data formats,
--- elfutils/src/elflint.c
+++ elfutils/src/elflint.c
2012-06-22 12:58:36 +00:00
@@ -123,6 +123,10 @@ static uint32_t shstrndx;
2008-08-27 08:19:16 +00:00
/* Array to count references in section groups. */
static int *scnref;
2005-08-24 22:10:14 +00:00
2010-01-15 03:59:06 +00:00
+/* Numbers of sections and program headers. */
2008-08-27 08:19:16 +00:00
+static unsigned int shnum;
2010-01-15 03:59:06 +00:00
+static unsigned int phnum;
2008-08-27 08:19:16 +00:00
+
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
int
main (int argc, char *argv[])
2012-06-22 12:58:36 +00:00
@@ -311,10 +315,19 @@ section_name (Ebl *ebl, int idx)
2008-08-27 08:19:16 +00:00
{
GElf_Shdr shdr_mem;
GElf_Shdr *shdr;
+ const char *ret;
+
+ if ((unsigned int) idx > shnum)
+ return "<invalid>";
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
shdr = gelf_getshdr (elf_getscn (ebl->elf, idx), &shdr_mem);
+ if (shdr == NULL)
+ return "<invalid>";
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- return elf_strptr (ebl->elf, shstrndx, shdr->sh_name);
+ ret = elf_strptr (ebl->elf, shstrndx, shdr->sh_name);
+ if (ret == NULL)
+ return "<invalid>";
+ return ret;
}
2005-08-24 22:10:14 +00:00
2008-05-13 00:44:12 +00:00
2012-06-22 12:58:36 +00:00
@@ -336,11 +349,6 @@ static const int valid_e_machine[] =
2008-08-27 08:19:16 +00:00
(sizeof (valid_e_machine) / sizeof (valid_e_machine[0]))
2008-05-13 00:44:12 +00:00
2010-01-15 03:59:06 +00:00
-/* Numbers of sections and program headers. */
2008-08-27 08:19:16 +00:00
-static unsigned int shnum;
2010-01-15 03:59:06 +00:00
-static unsigned int phnum;
2008-08-27 08:19:16 +00:00
-
-
static void
check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size)
{
2012-06-22 12:58:36 +00:00
@@ -624,7 +632,8 @@ section [%2d] '%s': symbol table cannot
2008-08-27 08:19:16 +00:00
}
}
2008-05-13 00:44:12 +00:00
2008-08-27 08:19:16 +00:00
- if (shdr->sh_entsize != gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT))
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT);
+ if (shdr->sh_entsize != sh_entsize)
ERROR (gettext ("\
section [%2u] '%s': entry size is does not match ElfXX_Sym\n"),
idx, section_name (ebl, idx));
2012-06-22 12:58:36 +00:00
@@ -662,7 +671,7 @@ section [%2d] '%s': XINDEX for zeroth en
2008-08-27 08:19:16 +00:00
xndxscnidx, section_name (ebl, xndxscnidx));
}
2008-05-13 00:44:12 +00:00
2008-08-27 08:19:16 +00:00
- for (size_t cnt = 1; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+ for (size_t cnt = 1; cnt < shdr->sh_size / sh_entsize; ++cnt)
{
sym = gelf_getsymshndx (data, xndxdata, cnt, &sym_mem, &xndx);
if (sym == NULL)
2012-06-22 12:58:36 +00:00
@@ -682,7 +691,8 @@ section [%2d] '%s': symbol %zu: invalid
2008-08-27 08:19:16 +00:00
else
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
name = elf_strptr (ebl->elf, shdr->sh_link, sym->st_name);
- assert (name != NULL);
+ assert (name != NULL
+ || strshdr->sh_type != SHT_STRTAB);
}
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
if (sym->st_shndx == SHN_XINDEX)
2012-06-22 12:58:36 +00:00
@@ -1031,9 +1041,11 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e
2008-08-27 08:19:16 +00:00
{
GElf_Shdr rcshdr_mem;
const GElf_Shdr *rcshdr = gelf_getshdr (scn, &rcshdr_mem);
- assert (rcshdr != NULL);
- if (rcshdr->sh_type == SHT_DYNAMIC)
+ if (rcshdr == NULL)
+ break;
+
+ if (rcshdr->sh_type == SHT_DYNAMIC && rcshdr->sh_entsize)
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
/* Found the dynamic section. Look through it. */
Elf_Data *d = elf_getdata (scn, NULL);
2012-06-22 12:58:36 +00:00
@@ -1043,7 +1055,9 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e
2008-08-27 08:19:16 +00:00
{
GElf_Dyn dyn_mem;
GElf_Dyn *dyn = gelf_getdyn (d, cnt, &dyn_mem);
- assert (dyn != NULL);
+
+ if (dyn == NULL)
+ break;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
if (dyn->d_tag == DT_RELCOUNT)
{
2012-06-22 12:58:36 +00:00
@@ -1057,7 +1071,9 @@ section [%2d] '%s': DT_RELCOUNT used for
2008-08-27 08:19:16 +00:00
/* Does the number specified number of relative
relocations exceed the total number of
relocations? */
- if (dyn->d_un.d_val > shdr->sh_size / shdr->sh_entsize)
+ if (shdr->sh_entsize != 0
+ && dyn->d_un.d_val > (shdr->sh_size
+ / shdr->sh_entsize))
ERROR (gettext ("\
section [%2d] '%s': DT_RELCOUNT value %d too high for this section\n"),
idx, section_name (ebl, idx),
2012-06-22 12:58:36 +00:00
@@ -1217,7 +1233,8 @@ section [%2d] '%s': no relocations for m
2008-08-27 08:19:16 +00:00
}
}
- if (shdr->sh_entsize != gelf_fsize (ebl->elf, reltype, 1, EV_CURRENT))
+ size_t sh_entsize = gelf_fsize (ebl->elf, reltype, 1, EV_CURRENT);
+ if (shdr->sh_entsize != sh_entsize)
ERROR (gettext (reltype == ELF_T_RELA ? "\
section [%2d] '%s': section entry size does not match ElfXX_Rela\n" : "\
section [%2d] '%s': section entry size does not match ElfXX_Rel\n"),
2012-06-22 12:58:36 +00:00
@@ -1440,7 +1457,8 @@ check_rela (Ebl *ebl, GElf_Ehdr *ehdr, G
2008-08-27 08:19:16 +00:00
Elf_Data *symdata = elf_getdata (symscn, NULL);
enum load_state state = state_undecided;
- for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELA, 1, EV_CURRENT);
+ for (size_t cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
GElf_Rela rela_mem;
GElf_Rela *rela = gelf_getrela (data, cnt, &rela_mem);
2012-06-22 12:58:36 +00:00
@@ -1490,7 +1508,8 @@ check_rel (Ebl *ebl, GElf_Ehdr *ehdr, GE
2008-08-27 08:19:16 +00:00
Elf_Data *symdata = elf_getdata (symscn, NULL);
enum load_state state = state_undecided;
- for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_REL, 1, EV_CURRENT);
+ for (size_t cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
GElf_Rel rel_mem;
GElf_Rel *rel = gelf_getrel (data, cnt, &rel_mem);
2012-06-22 12:58:36 +00:00
@@ -1589,7 +1608,8 @@ section [%2d] '%s': referenced as string
2008-08-27 08:19:16 +00:00
shdr->sh_link, section_name (ebl, shdr->sh_link),
idx, section_name (ebl, idx));
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- if (shdr->sh_entsize != gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT))
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT);
+ if (shdr->sh_entsize != sh_entsize)
ERROR (gettext ("\
section [%2d] '%s': section entry size does not match ElfXX_Dyn\n"),
idx, section_name (ebl, idx));
2012-06-22 12:58:36 +00:00
@@ -1599,7 +1619,7 @@ section [%2d] '%s': section entry size d
2008-08-27 08:19:16 +00:00
idx, section_name (ebl, idx));
bool non_null_warned = false;
- for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+ for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
GElf_Dyn dyn_mem;
GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dyn_mem);
2012-06-22 12:58:36 +00:00
@@ -1871,6 +1891,8 @@ section [%2d] '%s': entry size does not
2008-08-27 08:19:16 +00:00
idx, section_name (ebl, idx));
if (symshdr != NULL
+ && shdr->sh_entsize
+ && symshdr->sh_entsize
&& (shdr->sh_size / shdr->sh_entsize
< symshdr->sh_size / symshdr->sh_entsize))
ERROR (gettext ("\
2012-06-22 12:58:36 +00:00
@@ -1897,6 +1919,12 @@ section [%2d] '%s': extended section ind
2008-08-27 08:19:16 +00:00
}
Elf_Data *data = elf_getdata (elf_getscn (ebl->elf, idx), NULL);
+ if (data == NULL)
+ {
+ ERROR (gettext ("section [%2d] '%s': cannot get section data\n"),
+ idx, section_name (ebl, idx));
+ return;
+ }
if (*((Elf32_Word *) data->d_buf) != 0)
ERROR (gettext ("symbol 0 should have zero extended section index\n"));
2012-06-22 12:58:36 +00:00
@@ -1939,7 +1967,7 @@ section [%2d] '%s': hash table section i
2008-08-27 08:19:16 +00:00
size_t maxidx = nchain;
- if (symshdr != NULL)
+ if (symshdr != NULL && symshdr->sh_entsize != 0)
2006-07-12 22:08:26 +00:00
{
2008-08-27 08:19:16 +00:00
size_t symsize = symshdr->sh_size / symshdr->sh_entsize;
2012-06-22 12:58:36 +00:00
@@ -1950,18 +1978,28 @@ section [%2d] '%s': hash table section i
2008-08-27 08:19:16 +00:00
maxidx = symsize;
}
+ Elf32_Word *buf = (Elf32_Word *) data->d_buf;
+ Elf32_Word *end = (Elf32_Word *) ((char *) data->d_buf + shdr->sh_size);
size_t cnt;
for (cnt = 2; cnt < 2 + nbucket; ++cnt)
- if (((Elf32_Word *) data->d_buf)[cnt] >= maxidx)
+ {
+ if (buf + cnt >= end)
+ break;
+ else if (buf[cnt] >= maxidx)
ERROR (gettext ("\
section [%2d] '%s': hash bucket reference %zu out of bounds\n"),
idx, section_name (ebl, idx), cnt - 2);
+ }
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
for (; cnt < 2 + nbucket + nchain; ++cnt)
- if (((Elf32_Word *) data->d_buf)[cnt] >= maxidx)
+ {
+ if (buf + cnt >= end)
+ break;
+ else if (buf[cnt] >= maxidx)
ERROR (gettext ("\
section [%2d] '%s': hash chain reference %zu out of bounds\n"),
idx, section_name (ebl, idx), cnt - 2 - nbucket);
+ }
}
2005-08-24 22:10:14 +00:00
2012-06-22 12:58:36 +00:00
@@ -1991,18 +2029,28 @@ section [%2d] '%s': hash table section i
2008-08-27 08:19:16 +00:00
maxidx = symsize;
}
+ Elf64_Xword *buf = (Elf64_Xword *) data->d_buf;
+ Elf64_Xword *end = (Elf64_Xword *) ((char *) data->d_buf + shdr->sh_size);
size_t cnt;
for (cnt = 2; cnt < 2 + nbucket; ++cnt)
- if (((Elf64_Xword *) data->d_buf)[cnt] >= maxidx)
+ {
+ if (buf + cnt >= end)
+ break;
+ else if (buf[cnt] >= maxidx)
ERROR (gettext ("\
section [%2d] '%s': hash bucket reference %zu out of bounds\n"),
idx, section_name (ebl, idx), cnt - 2);
+ }
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
for (; cnt < 2 + nbucket + nchain; ++cnt)
- if (((Elf64_Xword *) data->d_buf)[cnt] >= maxidx)
+ {
+ if (buf + cnt >= end)
+ break;
+ else if (buf[cnt] >= maxidx)
ERROR (gettext ("\
section [%2d] '%s': hash chain reference %" PRIu64 " out of bounds\n"),
- idx, section_name (ebl, idx), (uint64_t) (cnt - 2 - nbucket));
+ idx, section_name (ebl, idx), (uint64_t) cnt - 2 - nbucket);
+ }
}
2008-01-22 01:09:23 +00:00
2005-08-24 22:10:14 +00:00
2012-06-22 12:58:36 +00:00
@@ -2027,7 +2075,7 @@ section [%2d] '%s': bitmask size not pow
2008-08-27 08:19:16 +00:00
if (shdr->sh_size < (4 + bitmask_words + nbuckets) * sizeof (Elf32_Word))
2005-08-24 22:10:14 +00:00
{
2008-08-27 08:19:16 +00:00
ERROR (gettext ("\
-section [%2d] '%s': hash table section is too small (is %ld, expected at least%ld)\n"),
+section [%2d] '%s': hash table section is too small (is %ld, expected at least %ld)\n"),
idx, section_name (ebl, idx), (long int) shdr->sh_size,
(long int) ((4 + bitmask_words + nbuckets) * sizeof (Elf32_Word)));
return;
2012-06-22 12:58:36 +00:00
@@ -2699,8 +2747,9 @@ section [%2d] '%s' refers in sh_link to
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* The number of elements in the version symbol table must be the
same as the number of symbols. */
- if (shdr->sh_size / shdr->sh_entsize
- != symshdr->sh_size / symshdr->sh_entsize)
+ if (shdr->sh_entsize && symshdr->sh_entsize
+ && (shdr->sh_size / shdr->sh_entsize
+ != symshdr->sh_size / symshdr->sh_entsize))
ERROR (gettext ("\
section [%2d] '%s' has different number of entries than symbol table [%2d] '%s'\n"),
idx, section_name (ebl, idx),
2009-01-24 01:16:36 +00:00
--- elfutils/src/readelf.c
+++ elfutils/src/readelf.c
2012-06-22 12:58:36 +00:00
@@ -1183,6 +1183,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
Elf32_Word *grpref = (Elf32_Word *) data->d_buf;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
GElf_Sym sym_mem;
+ GElf_Sym *sym = gelf_getsym (symdata, shdr->sh_info, &sym_mem);
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
printf ((grpref[0] & GRP_COMDAT)
? ngettext ("\
\nCOMDAT section group [%2zu] '%s' with signature '%s' contains %zu entry:\n",
2012-06-22 12:58:36 +00:00
@@ -1195,8 +1197,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
data->d_size / sizeof (Elf32_Word) - 1),
elf_ndxscn (scn),
elf_strptr (ebl->elf, shstrndx, shdr->sh_name),
- elf_strptr (ebl->elf, symshdr->sh_link,
- gelf_getsym (symdata, shdr->sh_info, &sym_mem)->st_name)
+ (sym == NULL ? NULL
+ : elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name))
?: gettext ("<INVALID SYMBOL>"),
data->d_size / sizeof (Elf32_Word) - 1);
2008-01-22 01:09:23 +00:00
2012-06-22 12:58:36 +00:00
@@ -1347,10 +1349,12 @@ static void
2008-08-27 08:19:16 +00:00
handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
{
int class = gelf_getclass (ebl->elf);
- GElf_Shdr glink;
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink;
Elf_Data *data;
size_t cnt;
size_t shstrndx;
2012-02-23 12:24:19 +00:00
+ size_t sh_entsize;
/* Get the data of the section. */
data = elf_getdata (scn, NULL);
2012-06-22 12:58:36 +00:00
@@ -1362,21 +1366,26 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn,
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
2005-08-24 22:10:14 +00:00
2012-02-23 12:24:19 +00:00
+ sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT);
+
2008-08-27 08:19:16 +00:00
+ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem);
+ if (glink == NULL)
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
printf (ngettext ("\
\nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
"\
2012-02-23 12:24:19 +00:00
\nDynamic segment contains %lu entries:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
- shdr->sh_size / shdr->sh_entsize),
- (unsigned long int) (shdr->sh_size / shdr->sh_entsize),
+ shdr->sh_size / sh_entsize),
+ (unsigned long int) (shdr->sh_size / sh_entsize),
2008-08-27 08:19:16 +00:00
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
shdr->sh_offset,
(int) shdr->sh_link,
- elf_strptr (ebl->elf, shstrndx,
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
- &glink)->sh_name));
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name));
fputs_unlocked (gettext (" Type Value\n"), stdout);
2012-02-23 12:24:19 +00:00
- for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+ for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
{
GElf_Dyn dynmem;
GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dynmem);
2012-06-22 12:58:36 +00:00
@@ -1525,7 +1534,8 @@ static void
2012-02-23 12:24:19 +00:00
handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
{
int class = gelf_getclass (ebl->elf);
- int nentries = shdr->sh_size / shdr->sh_entsize;
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_REL, 1, EV_CURRENT);
+ int nentries = shdr->sh_size / sh_entsize;
/* Get the data of the section. */
Elf_Data *data = elf_getdata (scn, NULL);
2012-06-22 12:58:36 +00:00
@@ -1711,7 +1721,8 @@ static void
2012-02-23 12:24:19 +00:00
handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr)
{
int class = gelf_getclass (ebl->elf);
- int nentries = shdr->sh_size / shdr->sh_entsize;
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELA, 1, EV_CURRENT);
+ int nentries = shdr->sh_size / sh_entsize;
/* Get the data of the section. */
Elf_Data *data = elf_getdata (scn, NULL);
2012-06-22 12:58:36 +00:00
@@ -1958,6 +1969,13 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
+ &glink_mem);
+ if (glink == NULL)
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
/* Now we can compute the number of entries in the section. */
unsigned int nsyms = data->d_size / (class == ELFCLASS32
? sizeof (Elf32_Sym)
2012-06-22 12:58:36 +00:00
@@ -1968,15 +1986,12 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
nsyms),
(unsigned int) elf_ndxscn (scn),
elf_strptr (ebl->elf, shstrndx, shdr->sh_name), nsyms);
- GElf_Shdr glink;
printf (ngettext (" %lu local symbol String table: [%2u] '%s'\n",
" %lu local symbols String table: [%2u] '%s'\n",
shdr->sh_info),
(unsigned long int) shdr->sh_info,
(unsigned int) shdr->sh_link,
- elf_strptr (ebl->elf, shstrndx,
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
- &glink)->sh_name));
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name));
2007-04-19 16:28:12 +00:00
2008-08-27 08:19:16 +00:00
fputs_unlocked (class == ELFCLASS32
? gettext ("\
2012-06-22 12:58:36 +00:00
@@ -2212,7 +2227,13 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn,
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- GElf_Shdr glink;
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
+ &glink_mem);
+ if (glink == NULL)
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
+
printf (ngettext ("\
\nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
"\
2012-06-22 12:58:36 +00:00
@@ -2223,9 +2244,7 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn,
2008-08-27 08:19:16 +00:00
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
shdr->sh_offset,
(unsigned int) shdr->sh_link,
- elf_strptr (ebl->elf, shstrndx,
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
- &glink)->sh_name));
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name));
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
unsigned int offset = 0;
for (int cnt = shdr->sh_info; --cnt >= 0; )
2012-06-22 12:58:36 +00:00
@@ -2278,8 +2297,14 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
+ &glink_mem);
+ if (glink == NULL)
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
int class = gelf_getclass (ebl->elf);
- GElf_Shdr glink;
printf (ngettext ("\
\nVersion definition section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
"\
2012-06-22 12:58:36 +00:00
@@ -2291,9 +2316,7 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
shdr->sh_offset,
(unsigned int) shdr->sh_link,
- elf_strptr (ebl->elf, shstrndx,
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
- &glink)->sh_name));
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name));
unsigned int offset = 0;
for (int cnt = shdr->sh_info; --cnt >= 0; )
2012-06-22 12:58:36 +00:00
@@ -2555,25 +2578,30 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G
2008-08-27 08:19:16 +00:00
filename = NULL;
}
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
+ &glink_mem);
2012-02-23 12:24:19 +00:00
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_HALF, 1, EV_CURRENT);
2008-08-27 08:19:16 +00:00
+ if (glink == NULL)
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
2008-01-22 01:09:23 +00:00
+
2008-08-27 08:19:16 +00:00
/* Print the header. */
- GElf_Shdr glink;
printf (ngettext ("\
\nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'",
"\
2012-02-23 12:24:19 +00:00
\nVersion symbols section [%2u] '%s' contains %d entries:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'",
- shdr->sh_size / shdr->sh_entsize),
+ shdr->sh_size / sh_entsize),
(unsigned int) elf_ndxscn (scn),
elf_strptr (ebl->elf, shstrndx, shdr->sh_name),
- (int) (shdr->sh_size / shdr->sh_entsize),
+ (int) (shdr->sh_size / sh_entsize),
2008-08-27 08:19:16 +00:00
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
shdr->sh_offset,
(unsigned int) shdr->sh_link,
- elf_strptr (ebl->elf, shstrndx,
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
- &glink)->sh_name));
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name));
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Now we can finally look at the actual contents of this section. */
2012-02-23 12:24:19 +00:00
- for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
+ for (unsigned int cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
{
if (cnt % 2 == 0)
printf ("\n %4d:", cnt);
2012-06-22 12:58:36 +00:00
@@ -2622,7 +2650,17 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn,
2008-08-27 08:19:16 +00:00
for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt)
++counts[lengths[cnt]];
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
- GElf_Shdr glink;
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf,
+ shdr->sh_link),
+ &glink_mem);
+ if (glink == NULL)
+ {
+ error (0, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
+ return;
+ }
+
printf (ngettext ("\
\nHistogram for bucket list length in section [%2u] '%s' (total of %d bucket):\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
"\
2012-06-22 12:58:36 +00:00
@@ -2635,9 +2673,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn,
2008-08-27 08:19:16 +00:00
shdr->sh_addr,
shdr->sh_offset,
(unsigned int) shdr->sh_link,
- elf_strptr (ebl->elf, shstrndx,
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
- &glink)->sh_name));
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name));
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (extrastr != NULL)
fputs (extrastr, stdout);
2012-06-22 12:58:36 +00:00
@@ -2897,7 +2933,8 @@ print_liblist (Ebl *ebl)
2012-02-23 12:24:19 +00:00
if (shdr != NULL && shdr->sh_type == SHT_GNU_LIBLIST)
{
- int nentries = shdr->sh_size / shdr->sh_entsize;
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_LIB, 1, EV_CURRENT);
+ int nentries = shdr->sh_size / sh_entsize;
printf (ngettext ("\
\nLibrary list section [%2zu] '%s' at offset %#0" PRIx64 " contains %d entry:\n",
"\
2012-06-22 12:58:36 +00:00
@@ -4644,6 +4681,16 @@ print_debug_aranges_section (Dwfl_Module
2008-08-27 08:19:16 +00:00
return;
}
+ GElf_Shdr glink_mem;
+ GElf_Shdr *glink;
+ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem);
+ if (glink == NULL)
+ {
+ error (0, 0, gettext ("invalid sh_link value in section %Zu"),
+ elf_ndxscn (scn));
+ return;
+ }
+
printf (ngettext ("\
2009-01-24 01:16:36 +00:00
\nDWARF section [%2zu] '%s' at offset %#" PRIx64 " contains %zu entry:\n",
2008-08-27 08:19:16 +00:00
"\
2009-01-24 01:16:36 +00:00
--- elfutils/src/strip.c
+++ elfutils/src/strip.c
2012-06-22 12:58:36 +00:00
@@ -564,6 +564,11 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
goto fail_close;
}
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
+ if (shstrndx >= shnum)
+ goto illformed;
+
+#define elf_assert(test) do { if (!(test)) goto illformed; } while (0)
+
/* Storage for section information. We leave room for two more
entries since we unconditionally create a section header string
table. Maybe some weird tool created an ELF file without one.
2012-06-22 12:58:36 +00:00
@@ -585,7 +590,7 @@ handle_elf (int fd, Elf *elf, const char
2007-04-19 16:28:12 +00:00
{
2008-08-27 08:19:16 +00:00
/* This should always be true (i.e., there should not be any
holes in the numbering). */
- assert (elf_ndxscn (scn) == cnt);
+ elf_assert (elf_ndxscn (scn) == cnt);
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
shdr_info[cnt].scn = scn;
2005-08-24 22:10:14 +00:00
2012-06-22 12:58:36 +00:00
@@ -598,6 +603,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
shdr_info[cnt].shdr.sh_name);
if (shdr_info[cnt].name == NULL)
2007-04-19 16:28:12 +00:00
{
2008-08-27 08:19:16 +00:00
+ illformed:
error (0, 0, gettext ("illformed file '%s'"), fname);
goto fail_close;
}
2012-06-22 12:58:36 +00:00
@@ -607,6 +613,8 @@ handle_elf (int fd, Elf *elf, const char
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
/* Remember the shdr.sh_link value. */
shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link;
+ if (shdr_info[cnt].old_sh_link >= shnum)
+ goto illformed;
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
/* Sections in files other than relocatable object files which
are not loaded can be freely moved by us. In relocatable
2012-06-22 12:58:36 +00:00
@@ -619,7 +627,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
appropriate reference. */
if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX))
{
- assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0);
+ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0);
shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt;
2008-01-22 01:09:23 +00:00
}
2008-08-27 08:19:16 +00:00
else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP))
2012-06-22 12:58:36 +00:00
@@ -636,7 +644,12 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
for (inner = 1;
inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
++inner)
+ {
+ if (grpref[inner] < shnum)
shdr_info[grpref[inner]].group_idx = cnt;
+ else
+ goto illformed;
+ }
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
if (inner == 1 || (inner == 2 && (grpref[0] & GRP_COMDAT) == 0))
/* If the section group contains only one element and this
2012-06-22 12:58:36 +00:00
@@ -647,7 +660,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
}
else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym))
2008-01-22 01:09:23 +00:00
{
2008-08-27 08:19:16 +00:00
- assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0);
+ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0);
shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt;
}
2005-08-24 22:10:14 +00:00
2012-06-22 12:58:36 +00:00
@@ -655,7 +668,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
discarded right away. */
if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0)
2008-01-22 01:09:23 +00:00
{
2008-08-27 08:19:16 +00:00
- assert (shdr_info[cnt].group_idx != 0);
+ elf_assert (shdr_info[cnt].group_idx != 0);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (shdr_info[shdr_info[cnt].group_idx].idx == 0)
{
2012-06-22 12:58:36 +00:00
@@ -731,10 +744,14 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
{
/* If a relocation section is marked as being removed make
sure the section it is relocating is removed, too. */
- if ((shdr_info[cnt].shdr.sh_type == SHT_REL
+ if (shdr_info[cnt].shdr.sh_type == SHT_REL
|| shdr_info[cnt].shdr.sh_type == SHT_RELA)
- && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0)
2012-02-23 12:24:19 +00:00
- shdr_info[cnt].idx = 1;
2008-08-27 08:19:16 +00:00
+ {
+ if (shdr_info[cnt].shdr.sh_info >= shnum)
+ goto illformed;
+ else if (shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0)
2012-02-23 12:24:19 +00:00
+ shdr_info[cnt].idx = 1;
+ }
2008-01-22 01:09:23 +00:00
2012-02-23 12:24:19 +00:00
/* If a group section is marked as being removed make
sure all the sections it contains are being removed, too. */
2012-06-22 12:58:36 +00:00
@@ -778,7 +795,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
if (shdr_info[cnt].symtab_idx != 0
&& shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
{
- assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB);
+ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB);
shdr_info[shdr_info[cnt].symtab_idx].data
= elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
2012-06-22 12:58:36 +00:00
@@ -818,6 +835,9 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
else if (scnidx == SHN_XINDEX)
scnidx = xndx;
+ if (scnidx >= shnum)
+ goto illformed;
+
if (shdr_info[scnidx].idx == 0)
/* This symbol table has a real symbol in
a discarded section. So preserve the
2012-06-22 12:58:36 +00:00
@@ -848,12 +868,16 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
}
/* Handle references through sh_info. */
- if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)
- && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0)
+ if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
+ {
+ if (shdr_info[cnt].shdr.sh_info >= shnum)
+ goto illformed;
+ else if ( shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0)
{
shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1;
changes |= shdr_info[cnt].shdr.sh_info < cnt;
}
+ }
/* Mark the section as investigated. */
shdr_info[cnt].idx = 2;
2012-06-22 12:58:36 +00:00
@@ -994,7 +1018,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0, gettext ("while generating output file: %s"),
elf_errmsg (-1));
- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
/* Add this name to the section header string table. */
shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0);
2012-06-22 12:58:36 +00:00
@@ -1031,7 +1055,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0,
gettext ("while create section header section: %s"),
elf_errmsg (-1));
- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn);
if (shdr_info[cnt].data == NULL)
2012-06-22 12:58:36 +00:00
@@ -1087,7 +1111,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
error (EXIT_FAILURE, 0,
gettext ("while create section header section: %s"),
elf_errmsg (-1));
- assert (elf_ndxscn (shdr_info[cnt].newscn) == idx);
+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx);
/* Finalize the string table and fill in the correct indices in the
section headers. */
2012-06-22 12:58:36 +00:00
@@ -1177,20 +1201,20 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
NULL);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
- assert ((versiondata->d_size / sizeof (Elf32_Word))
+ elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
>= shdr_info[cnt].data->d_size / elsize);
}
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if (shdr_info[cnt].version_idx != 0)
{
- assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM);
+ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM);
/* This section has associated version
information. We have to modify that
information, too. */
versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn,
NULL);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
- assert ((versiondata->d_size / sizeof (GElf_Versym))
+ elf_assert ((versiondata->d_size / sizeof (GElf_Versym))
>= shdr_info[cnt].data->d_size / elsize);
}
2005-08-24 22:10:14 +00:00
2012-06-22 12:58:36 +00:00
@@ -1245,7 +1269,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
sec = shdr_info[sym->st_shndx].idx;
else
{
- assert (shndxdata != NULL);
+ elf_assert (shndxdata != NULL);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
sec = shdr_info[xshndx].idx;
}
2012-06-22 12:58:36 +00:00
@@ -1266,7 +1290,7 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
nxshndx = sec;
}
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
- assert (sec < SHN_LORESERVE || shndxdata != NULL);
+ elf_assert (sec < SHN_LORESERVE || shndxdata != NULL);
2008-01-22 01:09:23 +00:00
2008-08-27 08:19:16 +00:00
if ((inner != destidx || nshndx != sym->st_shndx
|| (shndxdata != NULL && nxshndx != xshndx))
2012-06-22 12:58:36 +00:00
@@ -1293,9 +1317,11 @@ handle_elf (int fd, Elf *elf, const char
2012-02-23 12:24:19 +00:00
{
size_t sidx = (sym->st_shndx != SHN_XINDEX
? sym->st_shndx : xshndx);
- assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION
- || (shdr_info[sidx].shdr.sh_type == SHT_GROUP
- && shdr_info[sidx].shdr.sh_info == inner));
+ elf_assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION
+ || ((shdr_info[sidx].shdr.sh_type
+ == SHT_GROUP)
+ && (shdr_info[sidx].shdr.sh_info
+ == inner)));
}
2008-08-27 08:19:16 +00:00
}
2008-01-22 01:09:23 +00:00
2012-06-22 12:58:36 +00:00
@@ -1483,11 +1509,11 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
{
GElf_Sym sym_mem;
GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem);
- assert (sym != NULL);
+ elf_assert (sym != NULL);
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
const char *name = elf_strptr (elf, strshndx,
sym->st_name);
- assert (name != NULL);
+ elf_assert (name != NULL);
size_t hidx = elf_hash (name) % nbucket;
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
if (bucket[hidx] == 0)
2012-06-22 12:58:36 +00:00
@@ -1506,8 +1532,8 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
else
{
/* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */
- assert (shdr_info[cnt].shdr.sh_entsize
2012-02-23 12:24:19 +00:00
- == sizeof (Elf64_Xword));
2008-08-27 08:19:16 +00:00
+ elf_assert (shdr_info[cnt].shdr.sh_entsize
2012-02-23 12:24:19 +00:00
+ == sizeof (Elf64_Xword));
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf;
2012-02-23 12:24:19 +00:00
2012-06-22 12:58:36 +00:00
@@ -1537,11 +1563,11 @@ handle_elf (int fd, Elf *elf, const char
2008-08-27 08:19:16 +00:00
{
GElf_Sym sym_mem;
GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem);
- assert (sym != NULL);
+ elf_assert (sym != NULL);
2005-08-24 22:10:14 +00:00
2008-08-27 08:19:16 +00:00
const char *name = elf_strptr (elf, strshndx,
sym->st_name);
- assert (name != NULL);
+ elf_assert (name != NULL);
size_t hidx = elf_hash (name) % nbucket;
if (bucket[hidx] == 0)