mirror of
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
synced 2024-11-26 21:33:42 +08:00
libkmod: check for trailing \0 in __ksymtab_strings
As per the documentation (man 5 elf) the section must be null terminated. Move the check further up and remove the no longer needed code trying to workaround non-compliant instances. Note: drop the erroneous +1 in the overflow (malloc size) calculation Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org> Link: https://github.com/kmod-project/kmod/pull/210 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
parent
069d314f8a
commit
e5ef157bd5
@ -647,7 +647,7 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
|
||||
char *itr;
|
||||
struct kmod_modversion *a;
|
||||
int count, err;
|
||||
size_t vec_size, tmp_size, total_size;
|
||||
size_t vec_size, total_size;
|
||||
|
||||
*array = NULL;
|
||||
|
||||
@ -664,6 +664,11 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
|
||||
if (size <= 1)
|
||||
return 0;
|
||||
|
||||
if (strings[size - 1] != '\0') {
|
||||
ELFDBG(elf, "section __ksymtab_strings does not end with \\0 byte");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
last = 0;
|
||||
for (i = 0, count = 0; i < size; i++) {
|
||||
if (strings[i] == '\0') {
|
||||
@ -675,13 +680,10 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
|
||||
last = i + 1;
|
||||
}
|
||||
}
|
||||
if (strings[i - 1] != '\0')
|
||||
count++;
|
||||
|
||||
/* sizeof(struct kmod_modversion) * count + size + 1 */
|
||||
/* sizeof(struct kmod_modversion) * count + size */
|
||||
if (umulsz_overflow(sizeof(struct kmod_modversion), count, &vec_size) ||
|
||||
uaddsz_overflow(size, vec_size, &tmp_size) ||
|
||||
uaddsz_overflow(1, tmp_size, &total_size)) {
|
||||
uaddsz_overflow(size, vec_size, &total_size)) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@ -708,15 +710,6 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
|
||||
last = i + 1;
|
||||
}
|
||||
}
|
||||
if (strings[i - 1] != '\0') {
|
||||
size_t slen = i - last;
|
||||
a[count].crc = 0;
|
||||
a[count].bind = KMOD_SYMBOL_GLOBAL;
|
||||
a[count].symbol = itr;
|
||||
memcpy(itr, strings + last, slen);
|
||||
itr[slen] = '\0';
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user