Just assert early that the page size isn't unreasonable small instead of corrupting memory later.
Signed-off-by: Mark Wielaard <[email protected]> --- libdw/ChangeLog | 5 +++++ libdw/dwarf_begin_elf.c | 1 + 2 files changed, 6 insertions(+) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 8970ff6..753bcae 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,5 +1,10 @@ 2015-06-18 Mark Wielaard <[email protected]> + * dwarf_begin_elf.c (dwarf_begin_elf): Assert page size is big enough + to hold a Dwarf. + +2015-06-18 Mark Wielaard <[email protected]> + * dwarf_getpubnames.c (get_offsets): Always free mem on error. 2015-06-18 Mark Wielaard <[email protected]> diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index 4e0d590..6d38946 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -365,6 +365,7 @@ dwarf_begin_elf (elf, cmd, scngrp) /* Default memory allocation size. */ size_t mem_default_size = sysconf (_SC_PAGESIZE) - 4 * sizeof (void *); + assert (sizeof (struct Dwarf) < mem_default_size); /* Allocate the data structure. */ Dwarf *result = (Dwarf *) calloc (1, sizeof (Dwarf) + mem_default_size); -- 1.8.3.1
