diff options
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/generic/libc-start.c | 2 | ||||
-rw-r--r-- | sysdeps/i386/backtrace.c | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/sysdeps/generic/libc-start.c b/sysdeps/generic/libc-start.c index 1e07929e7e..c1a4c1e55f 100644 --- a/sysdeps/generic/libc-start.c +++ b/sysdeps/generic/libc-start.c @@ -39,10 +39,10 @@ __libc_start_main (int (*main) (int, char **, char **), int argc, int *dummy_addr = &_dl_starting_up; __libc_multiple_libcs = dummy_addr && !_dl_starting_up; +#endif /* Store the lowest stack address. */ __libc_stack_end = stack_end; -#endif /* Set the global _environ variable correctly. */ __environ = &argv[argc + 1]; diff --git a/sysdeps/i386/backtrace.c b/sysdeps/i386/backtrace.c index 0d484c7723..5e84205b04 100644 --- a/sysdeps/i386/backtrace.c +++ b/sysdeps/i386/backtrace.c @@ -21,6 +21,11 @@ #include <execinfo.h> +/* This is a global variable set at program start time. It marks the + highest used stack address. */ +extern void *__libc_stack_end; + + /* This is the stack alyout we see with every stack frame. +-----------------+ +-----------------+ @@ -42,6 +47,7 @@ __backtrace (array, size) { /* We assume that all the code is generated with frame pointers set. */ register void *ebp __asm__ ("ebp"); + register void *esp __asm__ ("esp"); struct layout *current; int cnt = 0; @@ -49,8 +55,10 @@ __backtrace (array, size) current = (struct layout *) ebp; while (cnt < size) { - if (current == NULL) - /* This means the toplevel is reached. */ + if (current < esp || current > __libc_stack_end) + /* This means the address is out of range. Note that for the + toplevel we see a frame pointer with value NULL which clearly is + out of range. */ break; array[cnt++] = current->return_address; |