[Bug,libelf/28101] elf_strptr slow with address sanitizer, passes entire section range to memrchr.
Commit Message
https://sourceware.org/bugzilla/show_bug.cgi?id=28101
Mark Wielaard <mark at klomp dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mark at klomp dot org
--- Comment #1 from Mark Wielaard <mark at klomp dot org> ---
I think it really is a bug/performance issue in asan. But "optimizing" it in
libelf by first checking the last char is zero, before calling memrchr wouldn't
hurt (and should normally prevent a function call). Does the following help?
do {
if (to <= from)
@@ -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 (str[to - 1] == '\0'
+ || (to - from > 0 && memrchr (&str[from], '\0', to - from - 1) !=
NULL));
#else