util: Limit the stack walk to avoid referencing undefined memory.
diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c
index e9891fd..528a1c3 100644
--- a/src/gallium/auxiliary/util/u_debug_stack.c
+++ b/src/gallium/auxiliary/util/u_debug_stack.c
@@ -62,6 +62,8 @@
    
 #ifdef PIPE_ARCH_X86
    while(nr_frames) {
+      const void **next_frame_pointer;
+
       if(!frame_pointer)
          break;
       
@@ -72,7 +74,14 @@
          --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