strdup symbol names from kelf_base

strdup symbol names in kpatch_elf_locals and when noting down hint
instead of just copying pointers so that they are still usable after
we teardown/free kelf_base.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
This commit is contained in:
Artem Savkov 2018-10-17 10:15:16 +02:00
parent 7305d6c29a
commit c46191028e

View File

@ -2482,7 +2482,7 @@ static struct sym_compare_type *kpatch_elf_locals(struct kpatch_elf *kelf)
continue;
sym_array[i].type = sym->type;
sym_array[i++].name = sym->name;
sym_array[i++].name = strdup(sym->name);
}
sym_array[i].type = 0;
sym_array[i].name = NULL;
@ -3229,7 +3229,7 @@ int main(int argc, char *argv[])
struct symbol *sym;
char *hint = NULL, *orig_obj, *patched_obj, *parent_name;
char *parent_symtab, *mod_symvers, *patch_name, *output_obj;
struct sym_compare_type *base_locals;
struct sym_compare_type *base_locals, *sym_comp;
arguments.debug = 0;
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
@ -3263,7 +3263,7 @@ int main(int argc, char *argv[])
list_for_each_entry(sym, &kelf_base->symbols, list) {
if (sym->type == STT_FILE) {
hint = sym->name;
hint = strdup(sym->name);
break;
}
}
@ -3275,7 +3275,11 @@ int main(int argc, char *argv[])
/* create symbol lookup table */
base_locals = kpatch_elf_locals(kelf_base);
lookup = lookup_open(parent_symtab, mod_symvers, hint, base_locals);
for (sym_comp = base_locals; sym_comp->name; sym_comp++) {
free(sym_comp->name);
}
free(base_locals);
free(hint);
kpatch_mark_grouped_sections(kelf_patched);
kpatch_replace_sections_syms(kelf_base);