summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhei Makarov <serhei@serhei.io>2024-01-18 16:50:33 -0500
committerSerhei Makarov <serhei@serhei.io>2024-01-18 16:50:33 -0500
commitab97ae258f9aacf2b1daa94d67227f280fa3d472 (patch)
tree974ac862681b922944a9bddee48356cc593ed0ef
parentb5da60c2deca1322ff49e4d874022648af45fbda (diff)
eu-stacktrace WIP fixes: introduce a frame limit
Rarely, the unwinder can loop indefinitely. Guard against this, similarly to the code in stack.c.
-rw-r--r--src/stacktrace.c4
1 files changed, 4 insertions, 0 deletions
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));