mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

Blame SOURCES/satyr-0.13-limit-stacktrace-depth.patch

f41043
From 1c223116114ddf80609e79ec7ada0ec4a5a463f3 Mon Sep 17 00:00:00 2001
f41043
From: Martin Milata <mmilata@redhat.com>
f41043
Date: Wed, 27 Aug 2014 12:51:41 +0200
f41043
Subject: [SATYR PATCH 5/6] unwind: limit the number of frames unwound
f41043
f41043
Fixes rhbz#1133907.
f41043
f41043
Signed-off-by: Martin Milata <mmilata@redhat.com>
f41043
---
f41043
 lib/core_unwind_elfutils.c | 15 +++++++++++++--
f41043
 1 file changed, 13 insertions(+), 2 deletions(-)
f41043
f41043
diff --git a/lib/core_unwind_elfutils.c b/lib/core_unwind_elfutils.c
f41043
index 6b904c7..43d66be 100644
f41043
--- a/lib/core_unwind_elfutils.c
f41043
+++ b/lib/core_unwind_elfutils.c
f41043
@@ -29,10 +29,13 @@
f41043
 #include <stdio.h>
f41043
 #include <string.h>
f41043
 
f41043
+#define FRAME_LIMIT 1024
f41043
+
f41043
 struct frame_callback_arg
f41043
 {
f41043
     struct sr_core_thread *thread;
f41043
     char *error_msg;
f41043
+    unsigned nframes;
f41043
 };
f41043
 
f41043
 struct thread_callback_arg
f41043
@@ -41,7 +44,7 @@ struct thread_callback_arg
f41043
     char *error_msg;
f41043
 };
f41043
 
f41043
-static int CB_STOP_UNWIND = DWARF_CB_ABORT+1;
f41043
+static const int CB_STOP_UNWIND = DWARF_CB_ABORT+1;
f41043
 
f41043
 static int
f41043
 frame_callback(Dwfl_Frame *frame, void *data)
f41043
@@ -70,6 +73,13 @@ frame_callback(Dwfl_Frame *frame, void *data)
f41043
     frame_arg->thread->frames =
f41043
         sr_core_frame_append(frame_arg->thread->frames, result);
f41043
 
f41043
+    /* Avoid huge stacktraces from programs stuck in infinite recursion. */
f41043
+    frame_arg->nframes++;
f41043
+    if (frame_arg->nframes >= FRAME_LIMIT)
f41043
+    {
f41043
+        return CB_STOP_UNWIND;
f41043
+    }
f41043
+
f41043
     return DWARF_CB_OK;
f41043
 }
f41043
 
f41043
@@ -90,7 +100,8 @@ unwind_thread(Dwfl_Thread *thread, void *data)
f41043
     struct frame_callback_arg frame_arg =
f41043
     {
f41043
         .thread = result,
f41043
-        .error_msg = NULL
f41043
+        .error_msg = NULL,
f41043
+        .nframes = 0
f41043
     };
f41043
 
f41043
     int ret = dwfl_thread_getframes(thread, frame_callback, &frame_arg);
f41043
-- 
f41043
1.9.3
f41043