For modules with lots of sections cache_sections could blow up the stack
theoretically. Don't use alloca, but use malloc with explicit free.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
+2015-05-18 Mark Wielaard <mjw@redhat.com>
+
+ * derelocate.c (cache_sections): Allocate temporary newrefs and
+ sortrefs with malloc, not alloca. Always free them on return.
+
2015-05-07 Mark Wielaard <mjw@redhat.com>
* cu.c (intern_cu): Check for EOF and check cuoff points to a real
2015-05-07 Mark Wielaard <mjw@redhat.com>
* cu.c (intern_cu): Check for EOF and check cuoff points to a real
/* Recover relocatibility for addresses computed from debug information.
/* Recover relocatibility for addresses computed from debug information.
- Copyright (C) 2005-2010, 2013 Red Hat, Inc.
+ Copyright (C) 2005-2010, 2013, 2015 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
{
elf_error:
__libdwfl_seterrno (DWFL_E_LIBELF);
{
elf_error:
__libdwfl_seterrno (DWFL_E_LIBELF);
+ nrefs = -1;
+ goto free_refs;
}
bool check_reloc_sections = false;
}
bool check_reloc_sections = false;
if (unlikely (name == NULL))
goto elf_error;
if (unlikely (name == NULL))
goto elf_error;
- struct secref *newref = alloca (sizeof *newref);
+ struct secref *newref = malloc (sizeof *newref);
+ if (unlikely (newref == NULL))
+ {
+ nomem:
+ __libdwfl_seterrno (DWFL_E_NOMEM);
+ nrefs = -1;
+ goto free_refs;
+ }
+
newref->scn = scn;
newref->relocs = NULL;
newref->name = name;
newref->scn = scn;
newref->relocs = NULL;
newref->name = name;
}
mod->reloc_info = malloc (offsetof (struct dwfl_relocation, refs[nrefs]));
}
mod->reloc_info = malloc (offsetof (struct dwfl_relocation, refs[nrefs]));
- if (mod->reloc_info == NULL)
- {
- __libdwfl_seterrno (DWFL_E_NOMEM);
- return -1;
- }
+ if (unlikely (mod->reloc_info == NULL))
+ goto nomem;
+
+ struct secref **sortrefs = malloc (nrefs * sizeof sortrefs[0]);
+ if (unlikely (sortrefs == NULL))
+ goto nomem;
- struct secref **sortrefs = alloca (nrefs * sizeof sortrefs[0]);
for (size_t i = nrefs; i-- > 0; refs = refs->next)
sortrefs[i] = refs;
assert (refs == NULL);
for (size_t i = nrefs; i-- > 0; refs = refs->next)
sortrefs[i] = refs;
assert (refs == NULL);
mod->reloc_info->refs[i].end = sortrefs[i]->end;
}
mod->reloc_info->refs[i].end = sortrefs[i]->end;
}
if (unlikely (check_reloc_sections))
{
/* There was a reloc section that preceded its target section.
if (unlikely (check_reloc_sections))
{
/* There was a reloc section that preceded its target section.
+free_refs:
+ while (refs != NULL)
+ {
+ struct secref *ref = refs;
+ refs = ref->next;
+ free (ref);
+ }
+