summaryrefslogtreecommitdiffstats
path: root/lib/libelf/libelf_ehdr.c
diff options
context:
space:
mode:
authorkaiw <kaiw@FreeBSD.org>2010-07-21 10:25:02 +0000
committerkaiw <kaiw@FreeBSD.org>2010-07-21 10:25:02 +0000
commit49a7d97ce43a82f9cfa863a35ca5cc928d7caf1e (patch)
tree49e27eb10d72ea7dccf8d6dc7232254e881bb052 /lib/libelf/libelf_ehdr.c
parent800d46f6e4936589dbbae5ddea8fe956c0cc7500 (diff)
downloadFreeBSD-src-49a7d97ce43a82f9cfa863a35ca5cc928d7caf1e.zip
FreeBSD-src-49a7d97ce43a82f9cfa863a35ca5cc928d7caf1e.tar.gz
Perform additional checks when translating between file and memory
representations of ELF types. The ELF(3) API allows applications to request a conversion that is `in-place', i.e., with source and destinations data buffers being the same. However, the file and memory sizes of ELF sections that have additional internal structure, such as those of type `Elf_Note', or `Elf_GNU_Hash_Header', can be determined only known after the type-specific headers that comprise the first few words in these sections are read and translated. Pass in the size of destination buffer to type translation routines in "libelf_convert.m4" and have these routines return an error code if the translated data would not fit inside the destination buffer. Obtained from: elftoolchain MFC after: 1 month
Diffstat (limited to 'lib/libelf/libelf_ehdr.c')
-rw-r--r--lib/libelf/libelf_ehdr.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libelf/libelf_ehdr.c b/lib/libelf/libelf_ehdr.c
index e0c4886..3b83f2c 100644
--- a/lib/libelf/libelf_ehdr.c
+++ b/lib/libelf/libelf_ehdr.c
@@ -46,7 +46,7 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
{
Elf_Scn *scn;
size_t fsz;
- void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
+ int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
uint32_t shtype;
assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn));
@@ -63,7 +63,8 @@ _libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum,
return (0);
xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec);
- (*xlator)((char *) &scn->s_shdr, e->e_rawfile + shoff, (size_t) 1,
+ (*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr),
+ e->e_rawfile + shoff, (size_t) 1,
e->e_byteorder != LIBELF_PRIVATE(byteorder));
#define GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \
@@ -105,7 +106,7 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
size_t fsz, msz;
uint16_t phnum, shnum, strndx;
uint64_t shoff;
- void (*xlator)(char *_d, char *_s, size_t _c, int _swap);
+ int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap);
assert(ec == ELFCLASS32 || ec == ELFCLASS64);
@@ -167,7 +168,7 @@ _libelf_ehdr(Elf *e, int ec, int allocate)
return (ehdr);
xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec);
- (*xlator)(ehdr, e->e_rawfile, (size_t) 1,
+ (*xlator)(ehdr, msz, e->e_rawfile, (size_t) 1,
e->e_byteorder != LIBELF_PRIVATE(byteorder));
/*
OpenPOWER on IntegriCloud