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
}
#endif
#ifndef HAS_BUILTIN_STRCMP
static always_inline int builtin_strcmp(const char *cs, const char *ct)
#ifndef HAS_BUILTIN_STRNCMP
static always_inline int builtin_strncmp(const char *cs, const char *ct, size_t count)
{
unsigned char c1, c2;
while (1) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2)
return c1 < c2 ? -1 : 1;
if (!c1)
size_t i;
for (i = 0; i < count; i++) {
if (cs[i] != ct[i])
return cs[i] < ct[i] ? -1 : 1;
if (!cs[i])
break;
}
return 0;
......
......@@ -239,20 +239,14 @@ int vdso_fill_symtable(uintptr_t mem, size_t size, struct vdso_symtable *t)
continue;
addr = (uintptr_t)dynsymbol_names + sym->st_name;
if (__ptr_struct_oob(addr, sizeof(t->symbols[i].name),
mem, size))
if (__ptr_struct_oob(addr, VDSO_SYMBOL_MAX, mem, size))
continue;
name = (void *)addr;
/*
* 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))
if (builtin_strncmp(name, symbol, VDSO_SYMBOL_MAX))
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;
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