diff options
author | Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp> | 2016-10-13 09:16:48 +0900 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2016-10-13 11:24:03 +0200 |
commit | a24d52ac205b4983c80657b5aa2a7d90d7032837 (patch) | |
tree | 1fc2966e22391592ba4a6d94da7c68d86f64e51e /libelf | |
parent | 60b2bf1b08c621492410b24e469b2bdf58d167d5 (diff) | |
download | elfutils-a24d52ac205b4983c80657b5aa2a7d90d7032837.tar.gz |
Do not depend on some non-POSIX features.
Define/open code memrchr, rawmemchr, powerof2 and TEMP_FAILURE_RETRY if
not available through system headers.
Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libelf')
-rw-r--r-- | libelf/ChangeLog | 8 | ||||
-rw-r--r-- | libelf/elf_getarsym.c | 8 | ||||
-rw-r--r-- | libelf/elf_strptr.c | 30 |
3 files changed, 38 insertions, 8 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog index cf672bf2..35af7865 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,5 +1,13 @@ 2015-10-11 Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp> + * elf_getarsym.c (elf_getarsym): Open code rawmemchr when not + available. + * elf_strptr.c: Include stdbool.h. + (validate_str): New function. + (elf_strptr): Use validate_str instead of memrchr. + +2015-10-11 Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp> + * elf32_updatefile.c: Remove sys/param.h include. * elf32_updatenull.c: Likewise. Add system.h include. * elf_begin.c: Remove sys/param.h. diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c index 65c67cc8..d5f0ba43 100644 --- a/libelf/elf_getarsym.c +++ b/libelf/elf_getarsym.c @@ -297,7 +297,15 @@ elf_getarsym (Elf *elf, size_t *ptr) arsym[cnt].as_off = (*u32)[cnt]; arsym[cnt].as_hash = _dl_elf_hash (str_data); +#if HAVE_DECL_RAWMEMCHR str_data = rawmemchr (str_data, '\0') + 1; +#else + char c; + do { + c = *str_data; + str_data++; + } while (c); +#endif } /* At the end a special entry. */ diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c index ea210459..e72a3a36 100644 --- a/libelf/elf_strptr.c +++ b/libelf/elf_strptr.c @@ -32,6 +32,7 @@ #endif #include <libelf.h> +#include <stdbool.h> #include <stddef.h> #include "libelfP.h" @@ -52,6 +53,22 @@ get_zdata (Elf_Scn *strscn) return zdata; } +static bool validate_str (const char *str, size_t from, size_t to) +{ +#if HAVE_DECL_MEMRCHR + return memrchr (&str[from], '\0', to - from) != NULL; +#else + do { + if (to <= from) + return false; + + to--; + } while (str[to]); + + return true; +#endif +} + char * elf_strptr (Elf *elf, size_t idx, size_t offset) { @@ -166,8 +183,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset) { /* Make sure the string is NUL terminated. Start from the end, which very likely is a NUL char. */ - if (likely (memrchr (&strscn->zdata_base[offset], - '\0', sh_size - offset) != NULL)) + if (likely (validate_str (strscn->zdata_base, offset, sh_size))) result = &strscn->zdata_base[offset]; else __libelf_seterrno (ELF_E_INVALID_INDEX); @@ -185,8 +201,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset) /* Make sure the string is NUL terminated. Start from the end, which very likely is a NUL char. */ - if (likely (memrchr (&strscn->rawdata_base[offset], - '\0', sh_size - offset) != NULL)) + if (likely (validate_str (strscn->rawdata_base, offset, sh_size))) result = &strscn->rawdata_base[offset]; else __libelf_seterrno (ELF_E_INVALID_INDEX); @@ -203,10 +218,9 @@ elf_strptr (Elf *elf, size_t idx, size_t offset) { /* Make sure the string is NUL terminated. Start from the end, which very likely is a NUL char. */ - if (likely (memrchr ((char *) dl->data.d.d_buf - + (offset - dl->data.d.d_off), '\0', - (dl->data.d.d_size - - (offset - dl->data.d.d_off))) != NULL)) + if (likely (validate_str ((char *) dl->data.d.d_buf, + offset - dl->data.d.d_off, + dl->data.d.d_size))) result = ((char *) dl->data.d.d_buf + (offset - dl->data.d.d_off)); else |