Skip to content

Commit

Permalink
libkmod: stop copying symbol names in kmod_elf_get_symbols_symtab()
Browse files Browse the repository at this point in the history
Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <[email protected]>
Reviewed-by: Tobias Stoeckmann <[email protected]>
Link: #210
Signed-off-by: Lucas De Marchi <[email protected]>
  • Loading branch information
evelikov authored and lucasdemarchi committed Nov 15, 2024
1 parent e5ef157 commit 63e1039
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions libkmod/libkmod-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,9 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
{
uint64_t i, last, off, size;
const char *strings;
char *itr;
struct kmod_modversion *a;
int count, err;
size_t vec_size, total_size;
size_t total_size;

*array = NULL;

Expand Down Expand Up @@ -681,31 +680,25 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
}
}

/* sizeof(struct kmod_modversion) * count + size */
if (umulsz_overflow(sizeof(struct kmod_modversion), count, &vec_size) ||
uaddsz_overflow(size, vec_size, &total_size)) {
/* sizeof(struct kmod_modversion) * count */
if (umulsz_overflow(sizeof(struct kmod_modversion), count, &total_size)) {
return -ENOMEM;
}

*array = a = malloc(total_size);
if (*array == NULL)
return -errno;

itr = (char *)(a + count);
last = 0;
for (i = 0, count = 0; i < size; i++) {
if (strings[i] == '\0') {
size_t slen = i - last;
if (last == i) {
last = i + 1;
continue;
}
a[count].crc = 0;
a[count].bind = KMOD_SYMBOL_GLOBAL;
a[count].symbol = itr;
memcpy(itr, strings + last, slen);
itr[slen] = '\0';
itr += slen + 1;
a[count].symbol = strings + last;
count++;
last = i + 1;
}
Expand Down

0 comments on commit 63e1039

Please sign in to comment.