mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-18 00:58:31 +00:00
string.h/pie: use builtin strncmp instead of strcmp
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com> Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
parent
86cc00fb5f
commit
4c69339cd2
2 changed files with 10 additions and 18 deletions
|
|
@ -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;
|
||||
size_t i;
|
||||
|
||||
while (1) {
|
||||
c1 = *cs++;
|
||||
c2 = *ct++;
|
||||
if (c1 != c2)
|
||||
return c1 < c2 ? -1 : 1;
|
||||
if (!c1)
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue