From: Serhei Makarov Date: Thu, 18 Jan 2024 21:50:33 +0000 (-0500) Subject: eu-stacktrace WIP fixes: introduce a frame limit X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab97ae258f9aacf2b1daa94d67227f280fa3d472;p=thirdparty%2Felfutils.git eu-stacktrace WIP fixes: introduce a frame limit Rarely, the unwinder can loop indefinitely. Guard against this, similarly to the code in stack.c. --- diff --git a/src/stacktrace.c b/src/stacktrace.c index 5cd808915..fdd9c25b9 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));