From ab97ae258f9aacf2b1daa94d67227f280fa3d472 Mon Sep 17 00:00:00 2001 From: Serhei Makarov Date: Thu, 18 Jan 2024 16:50:33 -0500 Subject: eu-stacktrace WIP fixes: introduce a frame limit Rarely, the unwinder can loop indefinitely. Guard against this, similarly to the code in stack.c. --- src/stacktrace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/stacktrace.c b/src/stacktrace.c index 5cd80891..fdd9c25b 100644 --- a/src/stacktrace.c +++ b/src/stacktrace.c @@ -124,6 +124,8 @@ SYSPROF_ALIGNED_END(1); #endif // ifndef SYSPROF_CAPTURE_FRAME_STACK_USER #endif // ifdef HAVE_SYSPROF_4_HEADERS +static int maxframes = 256; + static char *input_path = NULL; static int input_fd = -1; static char *output_path = NULL; @@ -943,6 +945,8 @@ sysprof_unwind_frame_cb (Dwfl_Frame *state, void *arg) #endif struct sysprof_unwind_info *sui = (struct sysprof_unwind_info *)arg; + if (sui->n_addrs > maxframes) + return DWARF_CB_ABORT; if (sui->n_addrs >= sui->max_addrs) { sui->addrs = reallocarray (sui->addrs, sui->max_addrs + UNWIND_ADDR_INCREMENT, sizeof(Dwarf_Addr)); -- cgit v1.2.3