diff options
Diffstat (limited to 'rtemstoolkit/elftoolchain/libelf/elf_scn.c')
-rw-r--r-- | rtemstoolkit/elftoolchain/libelf/elf_scn.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/rtemstoolkit/elftoolchain/libelf/elf_scn.c b/rtemstoolkit/elftoolchain/libelf/elf_scn.c index 80444fd..d3e2747 100644 --- a/rtemstoolkit/elftoolchain/libelf/elf_scn.c +++ b/rtemstoolkit/elftoolchain/libelf/elf_scn.c @@ -24,7 +24,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> #include <sys/queue.h> #include <assert.h> @@ -32,11 +31,12 @@ #include <gelf.h> #include <libelf.h> #include <stddef.h> +#include <stdint.h> #include <stdlib.h> #include "_libelf.h" -LIBELF_VCSID("$Id: elf_scn.c 1077 2010-08-09 15:37:40Z jkoshy $"); +ELFTC_VCSID("$Id: elf_scn.c 3177 2015-03-30 18:19:41Z emaste $"); /* * Load an ELF section table and create a list of Elf_Scn structures. @@ -44,22 +44,25 @@ LIBELF_VCSID("$Id: elf_scn.c 1077 2010-08-09 15:37:40Z jkoshy $"); int _libelf_load_section_headers(Elf *e, void *ehdr) { - int ec, swapbytes; - size_t fsz, i, shnum; + Elf_Scn *scn; uint64_t shoff; - char *src; Elf32_Ehdr *eh32; Elf64_Ehdr *eh64; - Elf_Scn *scn; - int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap); + int ec, swapbytes; + unsigned char *src; + size_t fsz, i, shnum; + int (*xlator)(unsigned char *_d, size_t _dsz, unsigned char *_s, + size_t _c, int _swap); assert(e != NULL); assert(ehdr != NULL); assert((e->e_flags & LIBELF_F_SHDRS_LOADED) == 0); #define CHECK_EHDR(E,EH) do { \ - if (fsz != (EH)->e_shentsize || \ - shoff + fsz * shnum > e->e_rawsize) { \ + if (shoff > e->e_rawsize || \ + fsz != (EH)->e_shentsize || \ + shnum > SIZE_MAX / fsz || \ + fsz * shnum > e->e_rawsize - shoff) { \ LIBELF_SET_ERROR(HEADER, 0); \ return (0); \ } \ @@ -95,7 +98,7 @@ _libelf_load_section_headers(Elf *e, void *ehdr) if (!STAILQ_EMPTY(&e->e_u.e_elf.e_scn)) { assert(STAILQ_FIRST(&e->e_u.e_elf.e_scn) == STAILQ_LAST(&e->e_u.e_elf.e_scn, _Elf_Scn, s_next)); - + i = 1; src += fsz; } @@ -104,8 +107,8 @@ _libelf_load_section_headers(Elf *e, void *ehdr) if ((scn = _libelf_allocate_scn(e, i)) == NULL) return (0); - (*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr), src, - (size_t) 1, swapbytes); + (*xlator)((unsigned char *) &scn->s_shdr, sizeof(scn->s_shdr), + src, (size_t) 1, swapbytes); if (ec == ELFCLASS32) { scn->s_offset = scn->s_rawoff = |