From: Emil Velikov Date: Wed, 23 Oct 2024 16:19:53 +0000 (+0100) Subject: libkmod: stop copying symbol names in kmod_elf_get_symbols_symtab() X-Git-Tag: v34~103 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=63e10397b075838f25990158c5d1c4bfe5c5cce4;p=thirdparty%2Fkmod.git libkmod: stop copying symbol names in kmod_elf_get_symbols_symtab() Since the caller already copies the strings as needed, we can just point to the elf data directly. Signed-off-by: Emil Velikov Reviewed-by: Tobias Stoeckmann Link: https://github.com/kmod-project/kmod/pull/210 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index a1868815..2055a072 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -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; @@ -681,9 +680,8 @@ 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; } @@ -691,21 +689,16 @@ static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf, 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; }