diff options
-rw-r--r-- | libelf/ChangeLog | 5 | ||||
-rw-r--r-- | libelf/elf_strptr.c | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 62437c55..f521ed3d 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2021-07-19 Mark Wielaard <mark@klomp.org> + + * elf_strptr.c (validate_str): Check last char is zero first before + calling memrchr on the whole block. + 2021-06-09 Andrei Homescu <ah@immunant.com> * elf_getdata.c: Fix d_align for sections where alignment is larger diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c index 76f2caf1..79a24d25 100644 --- a/libelf/elf_strptr.c +++ b/libelf/elf_strptr.c @@ -56,7 +56,9 @@ get_zdata (Elf_Scn *strscn) 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; + // Check end first, which is likely a zero terminator, to prevent function call + return ((to > 0 && str[to - 1] == '\0') + || (to - from > 0 && memrchr (&str[from], '\0', to - from - 1) != NULL)); #else do { if (to <= from) |