Commit 4c69339c authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Pavel Emelyanov

string.h/pie: use builtin strncmp instead of strcmp

Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 86cc00fb
...@@ -31,17 +31,15 @@ static always_inline int builtin_memcmp(const void *cs, const void *ct, size_t c ...@@ -31,17 +31,15 @@ static always_inline int builtin_memcmp(const void *cs, const void *ct, size_t c
} }
#endif #endif
#ifndef HAS_BUILTIN_STRCMP #ifndef HAS_BUILTIN_STRNCMP
static always_inline int builtin_strcmp(const char *cs, const char *ct) static always_inline int builtin_strncmp(const char *cs, const char *ct, size_t count)
{ {
unsigned char c1, c2; size_t i;
while (1) { for (i = 0; i < count; i++) {
c1 = *cs++; if (cs[i] != ct[i])
c2 = *ct++; return cs[i] < ct[i] ? -1 : 1;
if (c1 != c2) if (!cs[i])
return c1 < c2 ? -1 : 1;
if (!c1)
break; break;
} }
return 0; return 0;
......
...@@ -239,20 +239,14 @@ int vdso_fill_symtable(uintptr_t mem, size_t size, struct vdso_symtable *t) ...@@ -239,20 +239,14 @@ int vdso_fill_symtable(uintptr_t mem, size_t size, struct vdso_symtable *t)
continue; continue;
addr = (uintptr_t)dynsymbol_names + sym->st_name; addr = (uintptr_t)dynsymbol_names + sym->st_name;
if (__ptr_struct_oob(addr, sizeof(t->symbols[i].name), if (__ptr_struct_oob(addr, VDSO_SYMBOL_MAX, mem, size))
mem, size))
continue; continue;
name = (void *)addr; name = (void *)addr;
/* if (builtin_strncmp(name, symbol, VDSO_SYMBOL_MAX))
* XXX: Hope will not go out of mem+size.
* (i.e. with broken elf or malicious pointer in header)
* Otherwise, we need builtin_strncmp.
*/
if (builtin_strcmp(name, symbol))
continue; continue;
builtin_memcpy(t->symbols[i].name, name, sizeof(t->symbols[i].name)); builtin_memcpy(t->symbols[i].name, name, VDSO_SYMBOL_MAX);
t->symbols[i].offset = (unsigned long)sym->st_value - load->p_vaddr; t->symbols[i].offset = (unsigned long)sym->st_value - load->p_vaddr;
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment