mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

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

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