util: Limit the stack walk to avoid referencing undefined memory.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 30 Apr 2009 12:10:58 +0000 (13:10 +0100)
committerKeith Whitwell <keithw@vmware.com>
Tue, 5 May 2009 12:14:50 +0000 (13:14 +0100)
src/gallium/auxiliary/util/u_debug_stack.c

index e9891fde8a383b4c9e77c78bf2c3c1356337136f..528a1c394befa0bf1dbb810f1c184cd968d9a5d7 100644 (file)
@@ -62,6 +62,8 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
    
 #ifdef PIPE_ARCH_X86
    while(nr_frames) {
+      const void **next_frame_pointer;
+
       if(!frame_pointer)
          break;
       
@@ -72,7 +74,14 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
          --nr_frames;
       }
       
-      frame_pointer = (const void **)frame_pointer[0];
+      next_frame_pointer = (const void **)frame_pointer[0];
+      
+      /* Limit the stack walk to avoid referencing undefined memory */
+      if((uintptr_t)next_frame_pointer <= (uintptr_t)frame_pointer ||
+         (uintptr_t)next_frame_pointer > (uintptr_t)frame_pointer + 64*1024)
+         break;
+      
+      frame_pointer = next_frame_pointer;
    }
 #endif